You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/list.md
+29-29Lines changed: 29 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -6,31 +6,31 @@ order: 8
6
6
7
7
## `v-for`
8
8
9
-
We can use the `v-for`directive to render a list of items based on an array. The `v-for`directive requires a special syntax in the form of `item in items`, where `items`is the source data array and `item`is an **alias** for the array element being iterated on:
9
+
我们用`v-for`指令根据一组数组的选项列表进行渲染。`v-for`指令需要以 `item in items` 形式的特殊语法,`items`是源数据数组并且 `item`是数组元素迭代的别名。
10
10
11
11
### 基本用法
12
12
13
13
```html
14
14
<ulid="example-1">
15
-
<liv-for="item in items">
16
-
{{ item.message }}
17
-
</li>
15
+
<liv-for="item in items">
16
+
{{ item.message }}
17
+
</li>
18
18
</ul>
19
19
```
20
20
21
21
```js
22
22
var example1 =newVue({
23
-
el:'#example-1',
24
-
data: {
25
-
items: [
26
-
{ message:'Foo' },
27
-
{ message:'Bar' }
28
-
]
29
-
}
23
+
el:'#example-1',
24
+
data: {
25
+
items: [
26
+
{message:'foo' },
27
+
{message:'Bar' }
28
+
]
29
+
}
30
30
})
31
31
```
32
32
33
-
Result:
33
+
结果:
34
34
35
35
{% raw %}
36
36
<ulid="example-1"class="demo">
@@ -56,7 +56,7 @@ var example1 = new Vue({
56
56
</script>
57
57
{% endraw %}
58
58
59
-
Inside`v-for`blocks we have full access to parent scope properties. `v-for`also supports an optional second argument for the index of the current item.
@@ -125,9 +125,9 @@ Similar to template `v-if`, you can also use a `<template>` tag with `v-for` to
125
125
</ul>
126
126
```
127
127
128
-
### Object v-for
128
+
### 对象迭代 v-for
129
129
130
-
You can also use `v-for`to iterate through the properties of an object.
130
+
你也可以用 `v-for`通过一个对象的属性来迭代。
131
131
132
132
```html
133
133
<ulid="repeat-object"class="demo">
@@ -150,7 +150,7 @@ new Vue({
150
150
})
151
151
```
152
152
153
-
Result:
153
+
结果:
154
154
155
155
{% raw %}
156
156
<ulid="repeat-object"class="demo">
@@ -172,35 +172,35 @@ new Vue({
172
172
</script>
173
173
{% endraw %}
174
174
175
-
You can also provide a second argument for the key:
175
+
你也可以提供第二个的参数为键名:
176
176
177
177
```html
178
178
<divv-for="(value, key) in object">
179
179
{{ key }} : {{ value }}
180
180
</div>
181
181
```
182
182
183
-
And another for the index:
183
+
第三个参数为索引:
184
184
185
185
```html
186
186
<divv-for="(value, key, index) in object">
187
187
{{ index }}. {{ key }} : {{ value }}
188
188
</div>
189
189
```
190
190
191
-
<pclass="tip">When iterating over an object, the order is based on the key enumeration order of `Object.keys()`, which is **not** guaranteed to be consistent across JavaScript engine implementations.</p>
`v-for`can also take an integer. In this case it will repeat the template that many times.
195
+
`v-for`也可以取整数。在这种情况下,它将重复多次模板
196
196
197
197
```html
198
198
<div>
199
199
<spanv-for="n in 10">{{ n }}</span>
200
200
</div>
201
201
```
202
202
203
-
Result:
203
+
结果:
204
204
205
205
{% raw %}
206
206
<divid="range"class="demo">
@@ -211,17 +211,17 @@ new Vue({ el: '#range' })
211
211
</script>
212
212
{% endraw %}
213
213
214
-
### Components and v-for
214
+
### 组件 和 v-for
215
215
216
-
> This section assumes knowledge of [Components](/guide/components.html). Feel free to skip it and come back later.
216
+
> 了解组件相关知识,查看 [组件](/guide/components.html) 。
217
217
218
-
You can directly use `v-for`on a custom component, like any normal element:
218
+
在自定义组件里,你可以像任何普通元素一样用 `v-for`。
219
219
220
220
```html
221
221
<my-componentv-for="item in items"></my-component>
222
222
```
223
223
224
-
However, this won't automatically pass any data to the component, because components have isolated scopes of their own. In order to pass the iterated data into the component, we should also use props:
0 commit comments