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

gkiely picture gkiely  Â·  3Comments

lmnsg picture lmnsg  Â·  3Comments

loki0609 picture loki0609  Â·  3Comments

finico picture finico  Â·  3Comments

aviggngyv picture aviggngyv  Â·  3Comments