Skip to content

Commit 56957e8

Browse files
authored
Merge pull request #122 from bhnddowinf/2.0-cn
14 校对完成
2 parents 184b3e1 + 6828b65 commit 56957e8

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/guide/render-function.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ Vue.component('anchored-heading', {
6464
})
6565
```
6666

67-
template 在这种场景中就表现的有些冗余了。虽然我们可以使用 `<slot></slot>` 来接收每一个级别的标题标签,在标题标签中添加相同的锚点元素。但是些都会被包裹在一个无用的 `div` 中,因为组件必须有根节点。
67+
template 在这种场景中就表现的有些冗余了。虽然我们重复使用 `<slot></slot>` 来接收每一个级别的标题标签,在标题标签中添加相同的锚点元素。但是些都会被包裹在一个无用的 `div` 中,因为组件必须有根节点。
6868

6969
虽然模板在大多数组件中都非常好用,但是在这里它就不是很简洁的了。那么,我们来尝试使用 `render` 函数重写上面的例子:
7070

7171
``` js
7272
Vue.component('anchored-heading', {
7373
render: function (createElement) {
7474
return createElement(
75-
'h' + this.level, // tag name
76-
this.$slots.default // array of children
75+
'h' + this.level, // tag name 标签名称
76+
this.$slots.default // 子组件中的阵列
7777
)
7878
},
7979
props: {
@@ -96,19 +96,19 @@ Vue.component('anchored-heading', {
9696
// @returns {VNode}
9797
createElement(
9898
// {String | Object | Function}
99-
// An HTML tag name, component options, or function
100-
// returning one of these. Required.
99+
// 一个 HTML 标签,组件设置,或一个函数
100+
// 必须 Return 上述其中一个
101101
'div',
102102

103103
// {Object}
104-
// A data object corresponding to the attributes
105-
// you would use in a template. Optional.
104+
// 一个对应属性的数据对象
105+
// 您可以在 template 中使用.可选项.
106106
{
107-
// (see details in the next section below)
107+
// (下一章,将详细说明相关细节)
108108
},
109109

110110
// {String | Array}
111-
// Children VNodes. Optional.
111+
// 子节点(VNodes). 可选项.
112112
[
113113
createElement('h1', 'hello world'),
114114
createElement(MyComponent, {
@@ -123,21 +123,22 @@ createElement(
123123

124124
### 完整数据对象
125125

126-
One thing to note: similar to how `v-bind:class` and `v-bind:style` have special treatment in templates, they have their own top-level fields in VNode data objects.
126+
有一件事要注意:在 templates 中,`v-bind:class``v-bind:style` ,会有特别的处理,他们在 VNode 数据对象中,为最高级配置。
127+
127128

128129
``` js
129130
{
130-
// 和`v-bind:class`一样
131+
// 和`v-bind:class`一样的 API
131132
'class': {
132133
foo: true,
133134
bar: false
134135
},
135-
// 和`v-bind:style`一样
136+
// 和`v-bind:style`一样的 API
136137
style: {
137138
color: 'red',
138139
fontSize: '14px'
139140
},
140-
// 普通的 HTML 属性
141+
// 正常的 HTML 特性
141142
attrs: {
142143
id: 'foo'
143144
},
@@ -159,9 +160,8 @@ One thing to note: similar to how `v-bind:class` and `v-bind:style` have special
159160
nativeOn: {
160161
click: this.nativeClickHandler
161162
},
162-
// Custom directives. Note that the binding's
163-
// oldValue cannot be set, as Vue keeps track
164-
// of it for you.
163+
// 自定义指令. 注意事项:不能对绑定的旧值设值
164+
// Vue 会为您持续追踨
165165
directives: [
166166
{
167167
name: 'my-custom-directive',
@@ -173,7 +173,7 @@ One thing to note: similar to how `v-bind:class` and `v-bind:style` have special
173173
}
174174
}
175175
],
176-
// The name of a slot if the child of a component
176+
// 如果子组件有定义 slot 的名称
177177
slot: 'name-of-slot'
178178
// 其他特殊顶层属性
179179
key: 'myKey',
@@ -253,7 +253,7 @@ render: function (createElement) {
253253

254254
## 使用 JavaScript 代替模板功能
255255

256-
无论什么都可以使用普通的 JavaScript 实现,而不用依赖 Vue 的 render 函数额外提供 API。比如, template 中的 `v-if``v-for`:
256+
无论什么都可以使用原生的 JavaScript 来实现,Vue 的 render 函数不会提供专用的 API。比如, template 中的 `v-if``v-for`:
257257

258258
``` html
259259
<ul v-if="items.length">
@@ -317,7 +317,7 @@ new Vue({
317317
}
318318
})
319319
```
320-
<p class="tip">将 `h` 作为 `createElement` 的别名是一个惯例,你会发现在 Vue 生态中,实际上必须依赖 JSX,如果 `h` 不可用, 会在应用中触发报错。</p>
320+
<p class="tip">将 `h` 作为 `createElement` 的别名是一个通用惯例,你会发现在 Vue 生态系统中,实际上必须用到 JSX,如果在作用域中 `h` 失去作用, 在应用中会触发报错。</p>
321321

322322
更多关于 JSX 映射到 JavaScript,阅读 [使用文档](https://github.com/vuejs/babel-plugin-transform-vue-jsx#usage)
323323

@@ -357,17 +357,14 @@ Vue.component('my-component', {
357357

358358
函数化组件只是一个函数,所以渲染开销也低很多。但同样它也有完整的组件封装,你需要知道这些, 比如:
359359

360-
Since functional components are just functions, they're much cheaper to render. They're also very useful as wrapper components. For example, when you need to:
361360

362361
- 程序化地在多个组件中选择一个
363362
- 在将 children, props, data 传递给子组件之前操作它们。
364363

365-
- Programmatically choose one of several other components to delegate to
366-
- Manipulate children, props, or data before passing them on to a child component
364+
367365

368366
下面是一个依赖传入 props 的值的 `smart-list` 组件例子,它能代表更多具体的组件:
369367

370-
Here's an example of a `smart-list` component that delegates to more specific components, depending on the props passed to it:
371368

372369
``` js
373370
var EmptyList = { /* ... */ }

0 commit comments

Comments
 (0)