@@ -93,19 +93,18 @@ Vue.component('anchored-heading', {
93
93
// @returns {VNode}
94
94
createElement (
95
95
// {String | Object | Function}
96
- // 一个 HTML 标签,组件选项,或一个函数
97
- // 必须 Return 上述其中一个
98
- ' div' ,
96
+ // 一个 HTML 标签字符串,组件选项对象,或者一个返回值类型为String/Object的函数,必要参数
97
+ ' div' ,
99
98
100
99
// {Object}
101
- // 一个对应属性的数据对象
102
- // 您可以在 template 中使用.可选项 .
100
+ // 一个包含模板相关属性的数据对象
101
+ // 这样, 您可以在 template 中使用这些属性.可选参数 .
103
102
{
104
- // (下一章,将详细说明相关细节 )
103
+ // (详情见下一节 )
105
104
},
106
105
107
106
// {String | Array}
108
- // 子节点(VNodes). 可选项 .
107
+ // 子节点(VNodes),可以是一个字符串或者一个数组. 可选参数 .
109
108
[
110
109
createElement (' h1' , ' hello world' ),
111
110
createElement (MyComponent, {
@@ -118,9 +117,8 @@ createElement(
118
117
)
119
118
```
120
119
121
- ### 完整数据对象
122
-
123
- 有一件事要注意:在 templates 中,` v-bind:class ` 和 ` v-bind:style ` ,会有特别的处理,他们在 VNode 数据对象中,为最高级配置。
120
+ ### 深入data object参数
121
+ 有一件事要注意:正如在模板语法中,` v-bind:class ` 和 ` v-bind:style ` ,会被特别对待一样,在 VNode 数据对象中,下列属性名是级别最高的字段。
124
122
125
123
126
124
``` js
@@ -153,13 +151,13 @@ createElement(
153
151
on: {
154
152
click: this .clickHandler
155
153
},
156
- // 仅对于组件,用于监听原生事件,而不是组件使用 vm.$emit 触发的事件。
154
+ // 仅对于组件,用于监听原生事件,而不是组件内部使用 vm.$emit 触发的事件。
157
155
nativeOn: {
158
156
click: this .nativeClickHandler
159
157
},
160
158
// 自定义指令. 注意事项:不能对绑定的旧值设值
161
- // Vue 会为您持续追踨
162
- directives: [
159
+ // Vue 会为您持续追踪
160
+ directives: [
163
161
{
164
162
name: ' my-custom-directive' ,
165
163
value: ' 2'
@@ -175,8 +173,8 @@ createElement(
175
173
scopedSlots: {
176
174
default : props => h (' span' , props .text )
177
175
},
178
- // 如果子组件有定义 slot 的名称
179
- slot: ' name-of-slot'
176
+ // 如果组件是其他组件的子组件,需为slot指定名称
177
+ slot: ' name-of-slot'
180
178
// 其他特殊顶层属性
181
179
key: ' myKey' ,
182
180
ref: ' myRef'
@@ -185,7 +183,7 @@ createElement(
185
183
186
184
### 完整示例
187
185
188
- 有了这方面的知识 ,我们现在可以完成我们最开始想实现的组件:
186
+ 有了这些知识 ,我们现在可以完成我们最开始想实现的组件:
189
187
190
188
``` js
191
189
var getChildrenTextContent = function (children ) {
@@ -229,14 +227,14 @@ Vue.component('anchored-heading', {
229
227
230
228
#### VNodes 必须唯一
231
229
232
- 所有组件树中的 VNodes 必须唯一 。这意味着,下面的 render function 是无效的:
230
+ 组件树中的所有 VNodes 必须是唯一的 。这意味着,下面的 render function 是无效的:
233
231
234
232
``` js
235
233
render : function (createElement ) {
236
234
var myParagraphVNode = createElement (' p' , ' hi' )
237
235
return createElement (' div' , [
238
- // Yikes - duplicate VNodes!
239
- myParagraphVNode, myParagraphVNode
236
+ // 错误-重复的VNodes
237
+ myParagraphVNode, myParagraphVNode
240
238
])
241
239
}
242
240
```
@@ -257,7 +255,7 @@ render: function (createElement) {
257
255
258
256
### ` v-if ` and ` v-for `
259
257
260
- 无论什么都可以使用原生的 JavaScript 来实现 ,Vue 的 render 函数不会提供专用的 API。比如, template 中的 ` v-if ` 和 ` v-for ` :
258
+ 由于使用原生的 JavaScript 来实现某些东西很简单 ,Vue 的 render 函数没有提供专用的 API。比如, template 中的 ` v-if ` 和 ` v-for ` :
261
259
262
260
``` html
263
261
<ul v-if =" items.length" >
@@ -281,7 +279,7 @@ render: function (createElement) {
281
279
282
280
### ` v-model `
283
281
284
- There is no direct ` v-model ` counterpart in render functions - you will have to implement the logic yourself :
282
+ render函数中没有与 ` v-model ` 相应的api - 你必须自己来实现相应的逻辑 :
285
283
286
284
``` js
287
285
render : function (createElement ) {
@@ -299,19 +297,19 @@ render: function (createElement) {
299
297
}
300
298
```
301
299
302
- This is the cost of going lower-level, but it also gives you much more control over the interaction details compared to ` v-model ` .
300
+ 这就是深入底层要付出的,尽管麻烦了一些,但相对于 ` v-model ` 来说,你可以更灵活地控制。
303
301
304
- ### Event & Key Modifiers
302
+ ### 事件 & 按键修饰符
305
303
306
- For the ` .capture ` and ` .once ` event modifiers , Vue offers prefixes that can be used with ` on ` :
304
+ 对于 ` .capture ` 和 ` .once ` 事件修饰符 , Vue 提供了相应的前缀可以用于 ` on ` :
307
305
308
306
| Modifier(s) | Prefix |
309
307
| ------ | ------ |
310
308
| ` .capture ` | ` ! ` |
311
309
| ` .once ` | ` ~ ` |
312
310
| ` .capture.once ` or<br >` .once.capture ` | ` ~! ` |
313
311
314
- For example :
312
+ 例如 :
315
313
316
314
``` javascript
317
315
on: {
@@ -321,7 +319,7 @@ on: {
321
319
}
322
320
```
323
321
324
- For all other event and key modifiers, no proprietary prefix is necessary, because you can simply use event methods in the handler :
322
+ 对于其他的修饰符, 前缀不是很重要, 因为你可以直接在事件处理函数中使用事件方法 :
325
323
326
324
| Modifier(s) | Equivalent in Handler |
327
325
| ------ | ------ |
@@ -331,30 +329,29 @@ For all other event and key modifiers, no proprietary prefix is necessary, becau
331
329
| Keys:<br >` .enter ` , ` .13 ` | ` if (event.keyCode !== 13) return ` (change ` 13 ` to [ another key code] ( http://keycode.info/ ) for other key modifiers) |
332
330
| Modifiers Keys:<br >` .ctrl ` , ` .alt ` , ` .shift ` , ` .meta ` | ` if (!event.ctrlKey) return ` (change ` ctrlKey ` to ` altKey ` , ` shiftKey ` , or ` metaKey ` , respectively) |
333
331
334
- Here's an example with all of these modifiers used together:
335
-
332
+ 这里是一个使用所有修饰符的例子:
336
333
``` javascript
337
334
on: {
338
335
keyup : function (event ) {
339
- // Abort if the element emitting the event is not
340
- // the element the event is bound to
341
- if (event .target !== event .currentTarget ) return
342
- // Abort if the key that went up is not the enter
343
- // key (13) and the shift key was not held down
344
- // at the same time
345
- if (! event .shiftKey || event .keyCode !== 13 ) return
346
- // Stop event propagation
347
- event .stopPropagation ()
348
- // Prevent the default keyup handler for this element
349
- event .preventDefault ()
336
+ // 如果触发事件的元素不是事件绑定的元素
337
+ // 则返回
338
+ if (event .target !== event .currentTarget ) return
339
+ // 如果按下去的不是enter键或者
340
+ // 没有同时按下shift键
341
+ // 则返回
342
+ if (! event .shiftKey || event .keyCode !== 13 ) return
343
+ // 阻止 事件冒泡
344
+ event .stopPropagation ()
345
+ // 阻止该元素默认的keyup事件
346
+ event .preventDefault ()
350
347
// ...
351
348
}
352
349
}
353
350
```
354
351
355
- ### Slots
352
+ ### slots
356
353
357
- You can access static slot contents as Arrays of VNodes from [ ` this.$slots ` ] ( http://vuejs.org/v2/api/#vm-slots ) :
354
+ 你可以从 [ ` this.$slots ` ] ( http://vuejs.org/v2/api/#vm-slots ) 获取VNodes列表中的静态内容 :
358
355
359
356
``` js
360
357
render : function (createElement ) {
0 commit comments