Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Commit dc8fa36

Browse files
Jinjiangveaba
andauthored
Translated some new content in src/api/ (#648)
* Translated some new content in src/api/ * Updated the translation of effect scope * Apply suggestions from code review Co-authored-by: Godpu <[email protected]> Co-authored-by: Godpu <[email protected]>
1 parent 7c9f30a commit dc8fa36

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

src/api/effect-scope.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
<!-- TODO: translation -->
2-
# Effect Scope API <Badge text="3.2+" />
1+
# Effect 作用域 API <Badge text="3.2+" />
32

43
:::info
5-
Effect scope is an advanced API primarily intended for library authors. For details on how to leverage this API, please consult its corresponding [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md).
4+
Effect 作用域是一个高阶的 API,主要服务于库作者。关于其使用细节请咨询相应的 [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md)
65
:::
76

87
## `effectScope`
98

10-
Creates an effect scope object which can capture the reactive effects (e.g. computed and watchers) created within it so that these effects can be disposed together.
9+
创建一个 effect 作用域对象,以捕获在其内部创建的响应式 effect (例如计算属性或侦听器),使得这些 effect 可以一起被处理。
1110

12-
**Typing:**
11+
**类型**
1312

1413
```ts
1514
function effectScope(detached?: boolean): EffectScope
1615

1716
interface EffectScope {
18-
run<T>(fn: () => T): T | undefined // undefined if scope is inactive
17+
run<T>(fn: () => T): T | undefined // 如果这个域不活跃则为 undefined
1918
stop(): void
2019
}
2120
```
2221

23-
**Example:**
22+
**示例**
2423

2524
```js
2625
const scope = effectScope()
@@ -33,27 +32,27 @@ scope.run(() => {
3332
watchEffect(() => console.log('Count: ', doubled.value))
3433
})
3534

36-
// to dispose all effects in the scope
35+
// 处理该作用域内的所有 effect
3736
scope.stop()
3837
```
3938

4039
## `getCurrentScope`
4140

42-
Returns the current active [effect scope](#effectscope) if there is one.
41+
如果有,则返回当前活跃的 [effect 作用域](#effectscope)
4342

44-
**Typing:**
43+
**类型**
4544

4645
```ts
4746
function getCurrentScope(): EffectScope | undefined
4847
```
4948

5049
## `onScopeDispose`
5150

52-
Registers a dispose callback on the current active [effect scope](#effectscope). The callback will be invoked when the associated effect scope is stopped.
51+
在当前活跃的 [effect 作用域](#effectscope)上注册一个处理回调。该回调会在相关的 effect 作用域结束之后被调用。
5352

54-
This method can be used as a non-component-coupled replacement of `onUnmounted` in reusable composition functions, since each Vue component's `setup()` function is also invoked in an effect scope.
53+
该方法在复用组合式函数时可用作 `onUmounted` 的非组件耦合替代品,因为每个 Vue 组件的 `setup()` 函数也同样在 effect 作用域内被调用。
5554

56-
**Typing:**
55+
**类型**
5756

5857
```ts
5958
function onScopeDispose(fn: () => void): void

src/api/global-api.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,11 @@ const AsyncComp = defineAsyncComponent({
235235

236236
**参考**[动态和异步组件](../guide/component-dynamic-async.html)
237237

238-
<!-- TODO: translation -->
239238
## defineCustomElement <Badge text="3.2+" />
240239

241-
This method accepts the same argument as [`defineComponent`](#definecomponent), but instead returns a native [Custom Element](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) that can be used within any framework, or with no frameworks at all.
240+
该方法接受和 [`defineComponent`](#definecomponent) 相同的参数,但是返回一个原生的[自定义元素](https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Using_custom_elements),该元素可以用于任意框架或不基于框架使用。
242241

243-
Usage example:
242+
用法示例:
244243

245244
```html
246245
<my-vue-element></my-vue-element>
@@ -249,26 +248,26 @@ Usage example:
249248
```js
250249
import { defineCustomElement } from 'vue'
251250
const MyVueElement = defineCustomElement({
252-
// normal Vue component options here
251+
// 这里是普通的 Vue 组件选项
253252
props: {},
254253
emits: {},
255254
template: `...`,
256-
// defineCustomElement only: CSS to be injected into shadow root
255+
// 只用于 defineCustomElement:注入到 shadow root 中的 CSS
257256
styles: [`/* inlined css */`]
258257
})
259-
// Register the custom element.
260-
// After registration, all `<my-vue-element>` tags on the page will be upgraded.
258+
// 注册该自定义元素。
259+
// 注册过后,页面上所有的 `<my-vue-element>` 标记会被升级。
261260
customElements.define('my-vue-element', MyVueElement)
262-
// You can also programmatically instantiate the element:
263-
// (can only be done after registration)
261+
// 你也可以用编程的方式初始化这个元素:
262+
// (在注册之后才可以这样做)
264263
document.body.appendChild(
265264
new MyVueElement({
266-
// initial props (optional)
265+
// 初始化的 prop (可选)
267266
})
268267
)
269268
```
270269

271-
For more details on building Web Components with Vue, especially with Single File Components, see [Vue and Web Components](/guide/web-components.html#building-custom-elements-with-vue).
270+
关于使用 Vue,尤其是通过单文件组件构建 Web Components 的更多细节,请查阅[Vue Web Components](/guide/web-components.html#使用-Vue-构建自定义元素)
272271

273272
## resolveComponent
274273

src/api/reactivity-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
- [响应性基础 API](/api/basic-reactivity.html)
66
- [Refs](/api/refs-api.html)
77
- [Computed 与 watch](/api/computed-watch-api.html)
8-
- [Effect Scope API](/api/effect-scope.html)<!-- TODO: translation -->
8+
- [Effect 作用域 API](/api/effect-scope.html)

src/api/sfc-spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<!-- TODO: translation -->
21
# SFC Syntax Specification
32

3+
<!-- TODO: translation -->
44
## Intro
55

66
A `*.vue` file is a custom file format that uses HTML-like syntax to describe a Vue component. Each `*.vue` file consists of three types of top-level language blocks: `<template>`, `<script>`, and `<style>`, and optionally additional custom blocks:

src/api/sfc-tooling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<!-- TODO: translation -->
21
# SFC Tooling
32

3+
<!-- TODO: translation -->
44
## Online Playgrounds
55

66
You don't need to install anything on your machine to try out Vue SFCs - there are many online playgrounds that allow you to do so right in the browser:

src/guide/web-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
We consider Vue and Web Components to be primarily complementary technologies. Vue has excellent support for both consuming and creating custom elements. Whether you are integrating custom elements into an existing Vue application, or using Vue to build and distribute custom elements, you are in good company.
77

8-
## Using Custom Elements in Vue
8+
## 使用 Vue 构建自定义元素
99

1010
Vue [scores a perfect 100% in the Custom Elements Everywhere tests](https://custom-elements-everywhere.com/libraries/vue/results/results.html). Consuming custom elements inside a Vue application largely works the same as using native HTML elements, with a few things to keep in mind:
1111

0 commit comments

Comments
 (0)