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
-**See also:**[Reactivity in Depth](../guide/reactivity.html)
265
265
266
-
### Vue.delete( target, key )
266
+
### Vue.delete( target, propertyName/index )
267
267
268
268
-**Arguments:**
269
269
-`{Object | Array} target`
270
-
-`{string | number} key/index`
270
+
-`{string | number} propertyName/index`
271
271
272
272
> Only in 2.2.0+: Also works with Array + index.
273
273
@@ -1576,11 +1576,11 @@ type: api
1576
1576
// `callback` is fired immediately with current value of `a`
1577
1577
```
1578
1578
1579
-
### vm.$set( target, key, value )
1579
+
### vm.$set( target, propertyName/index, value )
1580
1580
1581
1581
- **Arguments:**
1582
1582
- `{Object|Array} target`
1583
-
- `{string | number} key`
1583
+
- `{string | number} propertyName/index`
1584
1584
- `{any} value`
1585
1585
1586
1586
- **Returns:** the set value.
@@ -1591,11 +1591,11 @@ type: api
1591
1591
1592
1592
- **See also:** [Vue.set](#Vue-set)
1593
1593
1594
-
### vm.$delete( target, key )
1594
+
### vm.$delete( target, propertyName/index )
1595
1595
1596
1596
- **Arguments:**
1597
1597
- `{Object|Array} target`
1598
-
- `{string | number} key`
1598
+
- `{string | number} propertyName/index`
1599
1599
1600
1600
- **Usage:**
1601
1601
@@ -2013,7 +2013,7 @@ type: api
2013
2013
``` html
2014
2014
<div v-for="(item, index) in items"></div>
2015
2015
<div v-for="(val, key) in object"></div>
2016
-
<div v-for="(val, key, index) in object"></div>
2016
+
<div v-for="(val, name, index) in object"></div>
2017
2017
```
2018
2018
2019
2019
The default behavior of`v-for` will try to patch the elements in-place without moving them. To force it to reorder elements, you need to provide an ordering hint with the `key` special attribute:
<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>
206
+
<pclass="tip">When iterating over an object, the order is based on the enumeration order of `Object.keys()`, which is **not** guaranteed to be consistent across JavaScript engine implementations.</p>
207
207
208
-
## `key`
208
+
## Maintaining State
209
209
210
210
When Vue is updating a list of elements rendered with `v-for`, by default it uses an "in-place patch" strategy. If the order of the data items has changed, instead of moving the DOM elements to match the order of the items, Vue will patch each element in-place and make sure it reflects what should be rendered at that particular index. This is similar to the behavior of `track-by="$index"` in Vue 1.x.
211
211
212
-
This default mode is efficient, but only suitable **when your list render output does not rely on child component state or temporary DOM state (e.g. form input values)**.
212
+
This default mode is efficient, but **only suitable when your list render output does not rely on child component state or temporary DOM state (e.g. form input values)**.
213
213
214
-
To give Vue a hint so that it can track each node's identity, and thus reuse and reorder existing elements, you need to provide a unique `key` attribute for each item. An ideal value for `key` would be the unique id of each item. This special attribute is a rough equivalent to `track-by` in 1.x, but it works like an attribute, so you need to use `v-bind` to bind it to dynamic values (using shorthand here):
214
+
To give Vue a hint so that it can track each node's identity, and thus reuse and reorder existing elements, you need to provide a unique `key` attribute for each item:
215
215
216
216
```html
217
-
<divv-for="item in items":key="item.id">
217
+
<divv-for="item in items"v-bind:key="item.id">
218
218
<!-- content -->
219
219
</div>
220
220
```
221
221
222
-
It is recommended to provide a `key` with `v-for` whenever possible, unless the iterated DOM content is simple, or you are intentionally relying on the default behavior for performance gains.
222
+
It is recommended to provide a `key`attribute with `v-for` whenever possible, unless the iterated DOM content is simple, or you are intentionally relying on the default behavior for performance gains.
223
223
224
224
Since it's a generic mechanism for Vue to identify nodes, the `key` also has other uses that are not specifically tied to `v-for`, as we will see later in the guide.
225
225
@@ -313,7 +313,7 @@ vm.b = 2
313
313
// `vm.b` is NOT reactive
314
314
```
315
315
316
-
Vue does not allow dynamically adding new root-level reactive properties to an already created instance. However, it's possible to add reactive properties to a nested object using the `Vue.set(object, key, value)` method. For example, given:
316
+
Vue does not allow dynamically adding new root-level reactive properties to an already created instance. However, it's possible to add reactive properties to a nested object using the `Vue.set(object, propertyName, value)` method. For example, given:
Copy file name to clipboardExpand all lines: src/v2/guide/migration-vue-router.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@ var router = new VueRouter({
73
73
})
74
74
```
75
75
76
-
The array syntax allows more predictable route matching, since iterating over an object is not guaranteed to use the same key order across browsers.
76
+
The array syntax allows more predictable route matching, since iterating over an object is not guaranteed to use the same property order across browsers.
Copy file name to clipboardExpand all lines: src/v2/guide/migration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -186,7 +186,7 @@ When including an `index`, the argument order for arrays used to be `(index, val
186
186
187
187
### `v-for` Argument Order for Objects <sup>changed</sup>
188
188
189
-
When including a `key`, the argument order for objects used to be `(key, value)`. It is now `(value, key)` to be more consistent with common object iterators such as lodash's.
189
+
When including a property name/key, the argument order for objects used to be `(name, value)`. It is now `(value, name)` to be more consistent with common object iterators such as lodash's.
Copy file name to clipboardExpand all lines: src/v2/guide/reactivity.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ vm.b = 2
34
34
// `vm.b` is NOT reactive
35
35
```
36
36
37
-
Vue does not allow dynamically adding new root-level reactive properties to an already created instance. However, it's possible to add reactive properties to a nested object using the `Vue.set(object, key, value)` method:
37
+
Vue does not allow dynamically adding new root-level reactive properties to an already created instance. However, it's possible to add reactive properties to a nested object using the `Vue.set(object, propertyName, value)` method:
0 commit comments