Vue: Changing array item

Created on 18 Apr 2015  路  2Comments  路  Source: vuejs/vue

Following fiddle demonstrates issue: http://jsfiddle.net/z9qxmkuL/3/

Most helpful comment

You should avoid directly setting elements of a data-bound Array with indices, because those changes will not be picked up by Vue.js. Instead, use the augmented $set() method:

// same as `demo.items[0] = ...` but triggers view update
demo.items.$set(0, { childMsg: 'Changed!'})

Object.observe is the one to blame.

All 2 comments

You should avoid directly setting elements of a data-bound Array with indices, because those changes will not be picked up by Vue.js. Instead, use the augmented $set() method:

// same as `demo.items[0] = ...` but triggers view update
demo.items.$set(0, { childMsg: 'Changed!'})

Object.observe is the one to blame.

Oh here is use case for $set(). Thanks @simplesmiler :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paceband picture paceband  路  3Comments

loki0609 picture loki0609  路  3Comments

robertleeplummerjr picture robertleeplummerjr  路  3Comments

gkiely picture gkiely  路  3Comments

6pm picture 6pm  路  3Comments