Skip to content

Commit b2ac577

Browse files
authored
Merge pull request #71 from menpuji/2.0-cn
实例方法/事件 实例方法/生命周期
2 parents 7397356 + 6eb6c74 commit b2ac577

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/api/index.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,19 +1083,19 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
10831083

10841084
- **See also:** [Vue.delete](#Vue-delete)
10851085

1086-
## Instance Methods / Events
1086+
## 实例方法/事件
10871087

10881088
<h3 id="vm-on">vm.$on( event, callback )</h3>
10891089

1090-
- **Arguments:**
1090+
- **参数:**
10911091
- `{string} event`
10921092
- `{Function} callback`
10931093

1094-
- **Usage:**
1094+
- **用法:**
10951095

1096-
Listen for a custom event on the current vm. Events can be triggered by `vm.$emit`. The callback will receive all the additional arguments passed into these event-triggering methods.
1096+
监听当前实例上的自定义事件。事件可以由vm.$emit触发。传入这些方法的附加参数都会传入这个方法的回调。
10971097

1098-
- **Example:**
1098+
- **示例:**
10991099

11001100
``` js
11011101
vm.$on('test', function (msg) {
@@ -1107,129 +1107,129 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
11071107

11081108
<h3 id="vm-once">vm.$once( event, callback )</h3>
11091109

1110-
- **Arguments:**
1110+
- **参数:**
11111111
- `{string} event`
11121112
- `{Function} callback`
11131113

1114-
- **Usage:**
1114+
- **用法:**
11151115

1116-
Listen for a custom event, but only once. The listener will be removed once it triggers for the first time.
1116+
监听一个自定义事件,但是只触发一次,在第一次触发之后删除监听器。
11171117

11181118
<h3 id="vm-off">vm.$off( [event, callback] )</h3>
11191119

1120-
- **Arguments:**
1120+
- **参数:**
11211121
- `{string} [event]`
11221122
- `{Function} [callback]`
11231123

1124-
- **Usage:**
1124+
- **用法:**
11251125

1126-
Remove event listener(s).
1126+
删除事件监听器。
11271127

1128-
- If no arguments are provided, remove all event listeners;
1128+
- 如果没有参数,则删除所有的事件监听器;
11291129

1130-
- If only the event is provided, remove all listeners for that event;
1130+
- 如果只提供了事件,则删除这个事件所有的监听器;
11311131

1132-
- If both event and callback are given, remove the listener for that specific callback only.
1132+
- 如果同时提供了事件与回调,则只删除这个回调。
11331133

11341134
<h3 id="vm-emit">vm.$emit( event, [...args] )</h3>
11351135

1136-
- **Arguments:**
1136+
- **参数:**
11371137
- `{string} event`
11381138
- `[...args]`
11391139

1140-
Trigger an event on the current instance. Any additional arguments will be passed into the listener's callback function.
1140+
触发当前实例上的事件。附加参数都会传给监听器回调。
11411141

1142-
## Instance Methods / Lifecycle
1142+
## 实例方法 / 生命周期
11431143

11441144
<h3 id="vm-mount">vm.$mount( [elementOrSelector] )</h3>
11451145

1146-
- **Arguments:**
1146+
- **参数:**
11471147
- `{Element | string} [elementOrSelector]`
11481148
- `{boolean} [hydrating]`
11491149

1150-
- **Returns:** `vm` - the instance itself
1150+
- **返回值:** `vm` - 实例自身
11511151

1152-
- **Usage:**
1152+
- **用法:**
11531153

1154-
If a Vue instance didn't receive the `el` option at instantiation, it will be in "unmounted" state, without an associated DOM element. `vm.$mount()` can be used to manually start the mounting of an unmounted Vue instance.
1154+
如果 Vue 实例在实例化时没有收到 el 选项,则它处于“未挂载”状态,没有关联的 DOM 元素或片断。可以使用 vm.$mount() 手动地挂载一个未挂载的实例。
11551155

1156-
If `elementOrSelector` argument is not provided, the template will be rendered as an off-document element, and you will have to use native DOM API to insert it into the document yourself.
1156+
如果没有"elementOrSelector"参数,模板将被渲染为文档之外的的元素,并且你必须使用原生DOM API把它插入文档中。
11571157

1158-
The method returns the instance itself so you can chain other instance methods after it.
1158+
这个方法返回实例自身,因而可以链式调用其它实例方法。
11591159

1160-
- **Example:**
1160+
- **示例:**
11611161

11621162
``` js
11631163
var MyComponent = Vue.extend({
11641164
template: '<div>Hello!</div>'
11651165
})
11661166

1167-
// create and mount to #app (will replace #app)
1167+
// 创建并挂载到 #app (会替换 #app)
11681168
new MyComponent().$mount('#app')
11691169

1170-
// the above is the same as:
1170+
// 同上
11711171
new MyComponent({ el: '#app' })
11721172

1173-
// or, render off-document and append afterwards:
1173+
// 或者,在文档之外渲染并且随后挂载
11741174
var component = new MyComponent().$mount()
11751175
document.getElementById('app').appendChild(vm.$el)
11761176
```
11771177

1178-
- **See also:**
1179-
- [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
1180-
- [Server-Side Rendering](/guide/ssr.html)
1178+
- **另见:**
1179+
- [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
1180+
- [服务端渲染](/guide/ssr.html)
11811181

11821182
<h3 id="vm-forceUpdate">vm.$forceUpdate()</h3>
11831183

1184-
- **Usage:**
1184+
- **示例:**
11851185

1186-
Force the Vue instance to re-render. Note it does not affect all child components, only the instance itself and child components with inserted slot content.
1186+
迫使Vue实例重修渲染。注意它仅仅影响实例本身和插入插槽内容的子组件,而不是所有子组件。
11871187

11881188
<h3 id="vm-nextTick">vm.$nextTick( callback )</h3>
11891189

1190-
- **Arguments:**
1190+
- **参数:**
11911191
- `{Function} callback`
11921192

1193-
- **Usage:**
1193+
- **用法:**
11941194

1195-
Defer the callback to be executed after the next DOM update cycle. Use it immediately after you've changed some data to wait for the DOM update. This is the same as the global `Vue.nextTick`, except that the callback's `this` context is automatically bound to the instance calling this method.
1195+
将回调延迟到下次 DOM 更新循环之后执行。在修改数据之后立即使用它,然后等待 DOM 更新。它跟全局方法 Vue.nextTick 一样,不同的是回调的 this 自动绑定到调用它的实例上。
11961196

1197-
- **Example:**
1197+
- **示例:**
11981198

11991199
``` js
12001200
new Vue({
12011201
// ...
12021202
methods: {
12031203
// ...
12041204
example: function () {
1205-
// modify data
1205+
// 修改数据
12061206
this.message = 'changed'
1207-
// DOM is not updated yet
1207+
// DOM 还没有更新
12081208
this.$nextTick(function () {
1209-
// DOM is now updated
1210-
// `this` is bound to the current instance
1209+
// DOM 现在更新了
1210+
// `this` 绑定到当前实例
12111211
this.doSomethingElse()
12121212
})
12131213
}
12141214
}
12151215
})
12161216
```
12171217

1218-
- **See also:**
1218+
- **另见:**
12191219
- [Vue.nextTick](#Vue-nextTick)
1220-
- [Async Update Queue](/guide/reactivity.html#Async-Update-Queue)
1220+
- [异步更新队列](/guide/reactivity.html#Async-Update-Queue)
12211221

12221222
<h3 id="vm-destroy">vm.$destroy()</h3>
12231223

1224-
- **Usage:**
1224+
- **用法:**
12251225

1226-
Completely destroy a vm. Clean up its connections with other existing vms, unbind all its directives, turn off all event listeners.
1226+
完全销毁一个实例。清理它与其它实例的连接,解绑它的全部指令及事件监听器。
12271227

1228-
Triggers the `beforeDestroy` and `destroyed` hooks.
1228+
在"beforeDestroy"和"destroyed"之间触发。
12291229

1230-
<p class="tip">In normal use cases you shouldn't have to call this method yourself. Prefer controlling the lifecycle of child components in a data-driven fashion using `v-if` and `v-for`.</p>
1230+
<p class="tip">在大多数场景中你不应该调用这个方法。最好使用"v-if"和"v-for"指令以数据驱动的方式控制子组件的生命周期。</p>
12311231

1232-
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
1232+
- **另见:** [生命周期图示](/guide/instance.html#Lifecycle-Diagram)
12331233

12341234
## Directives
12351235

0 commit comments

Comments
 (0)