I use vue version 2.5.x
Example like below.
No matter how hard I click \"add item\" the button, no item show in page.
But the \"add item version 2\" wo
Replace : this.items[this.count.toString()] = this.count;
with Vue.set(this.items,this.count.toString(),this.count);
let app = new Vue({
el: "#app",
data: {
items: {},
count: 0,
},
methods: {
add() {
Vue.set(this.items,this.count.toString(),this.count);
this.count++;
console.log(this.items);
},
add2() {
let items = {}
items[this.count.toString()] = this.count;
this.items = items;
this.count++;
console.log(this.items);
}
}
})
https://jsfiddle.net/zbb57ozv/
It's a limitations of javascript or Vue js caveat . check out section Change Detection Caveats of vue document for more information : Vue-Js Reactivity In Depth