Skip to content

Commit 5c569dd

Browse files
committed
Merge pull request #11 from Suixinlei/lang-zh
基本翻译,希望大家指正(另存在专业词汇无法翻译求帮助)
2 parents 4ec82c5 + 28bad84 commit 5c569dd

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

source/api/instance-methods.md

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ order: 4
55

66
## Data
77

8-
> You can observe data changes on a Vue instance. Note that all watch callbacks fire asynchronously. In addition, value changes are batched within an event loop. This means when a value changes multiple times within a single event loop, the callback will be fired only once with the latest value.
8+
> 你可以在Vue运行实例中监视数据的变化。你会注意到所有的watch回调都是异步发生的。而且,结果是在事件循环中被分批处理的。这就意味着一个结果假设在一次事件循环中改变多次,回调只会发生一次并直接变到最后的结果。
99
1010
### vm.$watch( expression, callback, [deep, immediate] )
1111

@@ -14,68 +14,70 @@ order: 4
1414
- **deep** `Boolean` *optional*
1515
- **immdediate** `Boolean` *optional*
1616

17-
Watch an expression on the Vue instance for changes. The expression can be a single keypath or actual expressions:
17+
监听在Vue实例中改变的一个表达式。表达式可以是一个单独的路径或者是一个实际的表达式:
1818

1919
``` js
2020
vm.$watch('a + b', function (newVal, oldVal) {
2121
// do something
2222
})
2323
```
2424

25-
To also detect nested value changes inside Objects, you need to pass in `true` for the third `deep` argument. Note that you don't need to do so to listen for Array mutations.
25+
也可以监视在对象中的属性,你需要为 `deep` 传递一个 `true` 来使用此功能 。
26+
27+
请注意你不可以这么监视用来数组中元素的变化。
2628

2729
``` js
2830
vm.$watch('someObject', callback, true)
2931
vm.someObject.nestedValue = 123
30-
// callback is fired
32+
// 回调被触发
3133
```
3234

33-
Passing in `true` for the fourth `immediate` argument will trigger the callback immediately with the current value of the expression:
35+
如果传递一个 `true` 到第四个变量 `immediate` , 那么回调会带着现在表达式的结果被立即触发。
3436

3537
``` js
3638
vm.$watch('a', callback, false, true)
37-
// callback is fired immediately with current value of `a`
39+
// 回调使用现在表达式的结果 `a` 被立刻触发
3840
```
3941

40-
Finally, `vm.$watch` returns an unwatch function that stops firing the callback:
42+
最后,还需要使用 `vm.$watch` 来返回一个停止监视的函数用来停止继续触发回调。
4143

4244
``` js
4345
var unwatch = vm.$watch('a', cb)
44-
// later, teardown the watcher
46+
// 最后,停止监制
4547
unwatch()
4648
```
4749

4850
### vm.$get( expression )
4951

5052
- **expression** `String`
5153

52-
Retrieve a value from the Vue instance given an expression. Expressions that throw errors will be suppressed and return `undefined`.
54+
Vue 实例传递一个表达式来获得结果,如果这个表达式带有错误,那么错误不会被报告并且返回一个 `undefined`
5355

5456
### vm.$set( keypath, value )
5557

5658
- **keypath** `String`
5759
- **value** `*`
5860

59-
Set a data value on the Vue instance given a valid keypath. If the path doesn't exist it will be created.
61+
通过给 Vue 实例传递一个可用的路径来设置结果,如果路径不存在那么会被创建。
6062

6163
### vm.$add( keypath, value )
6264

6365
- **keypath** `String`
6466
- **value** `*`
6567

66-
Add a root level property to the Vue instance (and also its `$data`). Due to the limitations of ES5, Vue cannot detect properties directly added to or deleted from an Object, so use this method and `vm.$delete` when you need to do so. Additionally, all observed objects are augmented with these two methods too.
68+
添加一个根等级(root level property)的属性到 Vue 实例(或者也可以说是它自己的 `$data`)。由于 ES5 的限制,Vue 不可以直接监视对象中属性的增加或者删除,所以当你需要做这些的时候请使用这个方法和 `vm.$delete`。另外,所以被监视的对象也都由这两个方法增大。
6769

6870
### vm.$delete( keypath )
6971

7072
- **keypath** `String`
7173

72-
Delete a root level property on the Vue instance (and also its `$data`).
74+
Vue 实例中删除一个根等级属性(或者是它的 `$data`)
7375

7476
### vm.$eval( expression )
7577

7678
- **expression** `String`
7779

78-
Evaluate an expression that can also contain filters.
80+
求一个表达式的值,它可以包含数个筛选器。
7981

8082
``` js
8183
// assuming vm.msg = 'hello'
@@ -88,6 +90,7 @@ vm.$eval('msg | uppercase') // -> 'HELLO'
8890

8991
Evaluate a piece of template string containing mustache interpolations. Note that this method simply performs string interpolation; attribute directives are not compiled.
9092

93+
9194
``` js
9295
// assuming vm.msg = 'hello'
9396
vm.$interpolate('{{msg}} world!') // -> 'hello world!'
@@ -97,7 +100,7 @@ vm.$interpolate('{{msg}} world!') // -> 'hello world!'
97100

98101
- **keypath** `String` *optional*
99102

100-
Log the current instance data as a plain object, which is more console-inspectable than a bunch of getter/setters. Also accepts an optional key.
103+
记录当前的实例数据保存在一个空白的对象,这种是比很多取值方法/设值方法都更有可检查性(console-inspectable)。当然也可以传递一个路径(可选)进去。
101104

102105
``` js
103106
vm.$log() // logs entire ViewModel data
@@ -106,110 +109,111 @@ vm.$log('item') // logs vm.item
106109

107110
## Events
108111

109-
> Each vm is also an event emitter. When you have multiple nested ViewModels, you can use the event system to communicate between them.
112+
> 每个 vm 都是一个事件的emitter。当你有很多的视图模型时,你可以用这种事件系统去在他们之间沟通数据。
110113
111114
### vm.$dispatch( event, [args...] )
112115

113116
- **event** `String`
114117
- **args...** *optional*
115118

116-
Dispatch an event from the current vm that propagates all the way up to its `$root`. If a callback returns `false`, it will stop the propagation at its owner instance.
119+
从当前的 vm 处理一个事件,这个 vm 一直传播到它的 `$root` 。如果其中一个回调返回了 `false` ,那么在它自己的实例中停止传播。
117120

118121
### vm.$broadcast( event, [args...] )
119122

120123
- **event** `String`
121124
- **args...** *optional*
122125

123-
Emit an event to all children vms of the current vm, which gets further broadcasted to their children all the way down. If a callback returns `false`, its owner instance will not broadcast the event any further.
126+
为当前 vm 的所有子 vm 注册该事件,这个 vm 会一直传播到到他的子vm。当一个回调返回 `false` 。当一个回调返回了 `false`,那么它的所有者实例就不会广播这个事件了。
124127

125128
### vm.$emit( event, [args...] )
126129

127130
- **event** `String`
128131
- **args...** *optional*
129132

130-
Trigger an event on this vm only.
133+
只在这个 vm 里面触发被传递的事件。
131134

132135
### vm.$on( event, callback )
133136

134137
- **event** `String`
135138
- **callback** `Function`
136139

137-
Listen for an event on the current vm.
140+
在当前 vm 中监听事件。
138141

139142
### vm.$once( event, callback )
140143

141144
- **event** `String`
142145
- **callback** `Function`
143146

144-
Attach a one-time only listener for an event.
147+
为一个事件注册一个一次性的监听器。
145148

146149
### vm.$off( [event, callback] )
147150

148151
- **event** `String` *optional*
149152
- **callback** `Function` *optional*
150153

151-
If no arguments are given, stop listening for all events; if only the event is given, remove all callbacks for that event; if both event and callback are given, remove that specific callback only.
154+
如果没有传递变量,那么停止监视所有时间;如果传递了一个事件,那么移除该事件的所有回调;如果事件和回调都被传递,则只移除该回调。
152155

153156
## DOM
154157

155-
> All vm DOM manipulation methods work like their jQuery counterparts - except they also trigger Vue.js transitions if there are any declared on vm's `$el`. For more details on transitions see [Adding Transition Effects](../guide/transitions.html).
158+
> 所有 vm 的操作 DOM 的方法都是类似于jQuery中相同功能一样 - 除了被声明为 vm 的 `$el` 会触发 Vue.js 的转换。对于转化的更多细节可以看 [Adding Transition Effects](../guide/transitions.html)
156159
157160
### vm.$appendTo( element|selector, [callback] )
158161

159162
- **element** `HTMLElement` | **selector** `String`
160163
- **callback** `Function` *optional*
161164

162-
Append the vm's `$el` to target element. The argument can be either an element or a querySelector string.
165+
在目标元素后面添加 vm 的 `$el` ,变量可以是一个元素或者是一个被选择器选中的字符串。
163166

164167
### vm.$before( element|selector, [callback] )
165168

166169
- **element** `HTMLElement` | **selector** `String`
167170
- **callback** `Function` *optional*
168171

169-
Insert the vm's `$el` before target element.
172+
在目标元素之前插入 vm 的 `$el`
170173

171174
### vm.$after( element|selector, [callback] )
172175

173176
- **element** `HTMLElement` | **selector** `String`
174177
- **callback** `Function` *optional*
175178

176-
Insert the vm's `$el` after target element.
179+
在目标元素之后插入 vm 的 `$el`
177180

178181
### vm.$remove( [callback] )
179182

180183
- **callback** `Function` *optional*
181184

182-
Remove the vm's `$el` from the DOM.
185+
从 DOM 中移除 vm 的 `$el`
183186

184187
## Lifecycle
185188

186189
### vm.$mount( [element|selector] )
187190

188191
- **element** `HTMLElement` | **selector** `String` *optional*
189192

190-
If the Vue instance didn't get an `el` option at instantiation, you can manually call `$mount()` to assign an element to it and start the compilation. If no argument is provided, an empty `<div>` will be automatically created. Calling `$mount()` on an already mounted instance will have no effect. The method returns the instance itself so you can chain other instance methods after it.
193+
如果 Vue 实例在实例化的时候没有被传递一个 `el` 的选项,你可以自己调用 `$mount()` 赋一个元素给它并且开始编译。如果没有变量提供,就会自动生成一个空的 `<div>` 。在已经被挂在的实例上调用 `$mount()` 上是没有作用的。这个方法会返回实例本身所以如果你可以在它后面连锁一些其他的实例方法。
191194

192195
### vm.$destroy( [remove] )
193196

194197
- **remove** `Boolean` *optional*
195198

196-
Completely destroy a vm. Clean up its connections with other existing vms, unbind all its directives and remove its `$el` from the DOM. Also, all `$on` and `$watch` listeners will be automatically removed.
199+
完全销毁一个 vm。清空它对其他存在的 vm 的连接,释放它的所有中间件并且从DOM中移除它的 `$el`。并且所有的 `$on` `$watch` 监听器也都会被自动移除。
197200

198201
### vm.$compile( element )
199202

200203
- **element** `HTMLElement`
201204

202-
Partially compile a piece of DOM (Element or DocumentFragment). The method returns a `decompile` function that tearsdown the directives created during the process. Note the decompile function does not remove the DOM. This method is exposed primarily for writing advanced custom directives.
205+
局部编译一个 DOM (元素或者是文档的片段)。这个方法返回一个 `decompile` 函数会关闭所有过程中已经被创建的中间件。请注意 decompile 函数不会移除DOM,这个方法对于写入高级自定义中间件来说根本上就是暴露的(exposed)。
206+
203207

204208
### vm.$addChild( [options, constructor] )
205209

206210
- **options** `Object` *optional*
207211
- **constructor** `Function` *optional*
208212

209-
Adds a child instance to the current instance. The options object is the same in manually instantiating an instance. Optionally you can pass in a constructor created from `Vue.extend()`.
213+
为当前的实例增加一个子实例。选项对象和手动实例化一个实例是相同的。传递一个用 `Vue.extend()` 创造的构造器进去也是可以的。
210214

211-
There are three implications of a parent-child relationship between instances:
215+
对于实例间父子关系有三种含义:
212216

213-
1. The parent and child can communicate via [the event system](#Events).
214-
2. The child has access to all parent assets (e.g. custom directives).
215-
3. The child, if inheriting parent scope, has access to parent scope data properties.
217+
1. 父实例和子实例可以通过[the event system](#Events)来沟通
218+
2. 子实例有对父实例所有资源的许可。(例子: 自定义中间件)
219+
3. 如果是继承了父实例作用域的子实例,那么对父实例作用域的数据属性也有许可

source/guide/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gz_size: 18.11
1919
<a class="button" href="https://raw.github.com/yyx990803/vue/{{vue_version}}/dist/vue.min.js" download>生产版本</a><span class="light info">{{min_size}}kb minified / {{gz_size}}kb gzipped</span>
2020
</div>
2121

22-
也可以在 [cdnjs](..//cdnjs.cloudflare.com/ajax/libs/vue/{{vue_version}}/vue.min.js) 使用 (版本更新会略滞后)。
22+
也可以在 [cdnjs](http://cdnjs.cloudflare.com/ajax/libs/vue/{{vue_version}}/vue.min.js) 使用 (版本更新会略滞后)。
2323

2424
## NPM
2525

0 commit comments

Comments
 (0)