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

fergaldoyle picture fergaldoyle  路  3Comments

wufeng87 picture wufeng87  路  3Comments

aviggngyv picture aviggngyv  路  3Comments

seemsindie picture seemsindie  路  3Comments

Jokcy picture Jokcy  路  3Comments