Skip to content

Commit 8481ade

Browse files
committed
Events/Lifecycle
1 parent 84f00a0 commit 8481ade

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

src/api/index.md

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

10821082
- **See also:** [Vue.delete](#Vue-delete)
10831083

1084-
## Instance Methods / Events
1084+
## 实例方法/事件
10851085

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

1088-
- **Arguments:**
1088+
- **参数:**
10891089
- `{string} event`
10901090
- `{Function} callback`
10911091

1092-
- **Usage:**
1092+
- **用法:**
10931093

1094-
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.
1094+
监听当前实例上的自定义事件。事件可以由vm.$emit触发。传入这些方法的附加参数都会传入这个方法的回调。
10951095

1096-
- **Example:**
1096+
- **示例:**
10971097

10981098
``` js
10991099
vm.$on('test', function (msg) {
@@ -1105,129 +1105,129 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
11051105

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

1108-
- **Arguments:**
1108+
- **参数:**
11091109
- `{string} event`
11101110
- `{Function} callback`
11111111

1112-
- **Usage:**
1112+
- **用法:**
11131113

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

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

1118-
- **Arguments:**
1118+
- **参数:**
11191119
- `{string} [event]`
11201120
- `{Function} [callback]`
11211121

1122-
- **Usage:**
1122+
- **用法:**
11231123

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

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

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

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

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

1134-
- **Arguments:**
1134+
- **参数:**
11351135
- `{string} event`
11361136
- `[...args]`
11371137

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

1140-
## Instance Methods / Lifecycle
1140+
## 实例方法 / 生命周期
11411141

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

1144-
- **Arguments:**
1144+
- **参数:**
11451145
- `{Element | string} [elementOrSelector]`
11461146
- `{boolean} [hydrating]`
11471147

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

1150-
- **Usage:**
1150+
- **用法:**
11511151

1152-
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.
1152+
如果 Vue 实例在实例化时没有收到 el 选项,则它处于“未挂载”状态,没有关联的 DOM 元素或片断。可以使用 vm.$mount() 手动地开始挂载/编译未挂载的实例。
11531153

1154-
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.
1154+
如果没有"elementOrSelector"参数,模板将被创建为文档之外的的片断,需要手工用其它的 DOM 实例方法把它插入文档中。如果 replace 选项为 false,则自动创建一个空 <div>,作为包装元素。
11551155

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

1158-
- **Example:**
1158+
- **示例:**
11591159

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

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

1168-
// the above is the same as:
1168+
// 同上
11691169
new MyComponent({ el: '#app' })
11701170

11711171
// or, render off-document and append afterwards:
11721172
var component = new MyComponent().$mount()
11731173
document.getElementById('app').appendChild(vm.$el)
11741174
```
11751175

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

11801180
<h3 id="vm-forceUpdate">vm.$forceUpdate()</h3>
11811181

1182-
- **Usage:**
1182+
- **示例:**
11831183

11841184
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.
11851185

11861186
<h3 id="vm-nextTick">vm.$nextTick( callback )</h3>
11871187

1188-
- **Arguments:**
1188+
- **参数:**
11891189
- `{Function} callback`
11901190

1191-
- **Usage:**
1191+
- **用法:**
11921192

1193-
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.
1193+
将回调延迟到下次 DOM 更新循环之后执行。在修改数据之后立即使用它,然后等待 DOM 更新。它跟全局方法 Vue.nextTick 一样,不同的是回调的 this 自动绑定到调用它的实例上。
11941194

1195-
- **Example:**
1195+
- **示例:**
11961196

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

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

12201220
<h3 id="vm-destroy">vm.$destroy()</h3>
12211221

1222-
- **Usage:**
1222+
- **用法:**
12231223

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

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

1228-
<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>
1228+
<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>
12291229

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

12321232
## Directives
12331233

0 commit comments

Comments
 (0)