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/v2/guide/list.md
+21-3Lines changed: 21 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -268,21 +268,39 @@ Due to limitations in JavaScript, Vue **cannot** detect the following changes to
268
268
1. When you directly set an item with the index, e.g. `vm.items[indexOfItem] = newValue`
269
269
2. When you modify the length of the array, e.g. `vm.items.length = newLength`
270
270
271
+
For example:
272
+
273
+
```js
274
+
var vm =newVue({
275
+
data: {
276
+
items: ['a', 'b', 'c']
277
+
}
278
+
})
279
+
vm.items[1] ='x'// is NOT reactive
280
+
vm.items.length=2// is NOT reactive
281
+
```
282
+
271
283
To overcome caveat 1, both of the following will accomplish the same as `vm.items[indexOfItem] = newValue`, but will also trigger state updates in the reactivity system:
272
284
273
285
```js
274
286
// Vue.set
275
-
Vue.set(example1.items, indexOfItem, newValue)
287
+
Vue.set(vm.items, indexOfItem, newValue)
276
288
```
277
289
```js
278
290
// Array.prototype.splice
279
-
example1.items.splice(indexOfItem, 1, newValue)
291
+
vm.items.splice(indexOfItem, 1, newValue)
292
+
```
293
+
294
+
You can also use the [`vm.$set`](https://vuejs.org/v2/api/#vm-set) instance method, which is an alias for the global `Vue.set`:
0 commit comments