computed to calculate property Eavesdropping not change the array elements

Simply record what the problems encountered

An event will change in the methods of elements in the array arr

clickBtn () {
  this.arr[0] = false
}

 

But change can not monitor the array of elements in computed in

isAble() {
  if (this.arr[i]) {
    return true;
  }
  return false;
}

The solution is to write in such methods in

clickBtn () {
  this.$set(this.arr, 0 ,false)
}

Thus it can be detected computed

this. The official explanation $ set () is this

Add a property to a responsive object and ensure that the new property is also responsive, and trigger view updates. It must be used to add new attributes to the responsive object because the new Vue unable to detect common attributes (such as  this.myObject.newProperty = 'hi')

https://cn.vuejs.org/v2/api/#Vue-set

supplement:

When you add a property to the objects you can output in the console, but the view is not updated, this time you need to use this. $ Set () the

This situation may be added to the first row in such a method

this.$forceUpdate();

Such layers may be re-rendered view

Guess you like

Origin www.cnblogs.com/wuyufei/p/12549494.html