javascript - Vue.set dynamically added attribute failure problem
PHPz
PHPz 2017-05-19 10:11:05
0
2
579

vue2 Problems encountered by novices developing small demos:

 

Vue.set(this.food, 'count', 1) dynamically adds attributes, but

is not displayed. What is the reason? How should we solve it?
Vue.set( object, key, value )

PHPz
PHPz

学习是最好的投资!

reply all (2)
曾经蜡笔没有小新
increaseCount : function () { if (!this.food.count) { this.food.count = 1 this.food.$set('count', 1) // 这里应该这么设置才有效 console.log(this.food) // Object {count: 1, __ob__: Observer} } else { this.food.count ++ }

    小葫芦

    props should be immutable.
    The data state is variable.
    And Vue.set dynamically sets the properties of the object, and this object should also exist in data.

    { data() { return { food: { } } }, methods: { increase() { Vue.set(this.food, 'count', 1); }, }, }
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!