The Boolean values in the vue change array are not changed on the page.

demo is here http://jsfiddle.net/mtcv824d/

<div id="app">
  <div @click="change(0)">
  {{arr[0]}}
  </div>
</div>
new Vue({
  el: "-sharpapp",
  data: {
    arr: [true, false, false]
  },
  methods: {
      change: function(index){
      alert(this.arr[index])
        this.arr[index] = !this.arr[index]
      alert(this.arr[index])
    }
  }
})
The output in the

method finds that the value has changed, but there is no change on the page. what is the reason?

Feb.20,2022

the document is written:
due to the limitation of JavaScript, Vue cannot detect the array of the following changes:

when you set an item directly using the index, for example: vm.items [indexOfItem] = newValue
when you modify the length of the array, for example: vm.items.length = newLength

ide/list.html-sharp%E6%95%B0%E7%BB%84%E6%9B%B4%E6%96%B0%E6%A3%80%E6%B5%8B" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.


you need to make a deep copy

// 
this.arr[index] = JSON.parse(JSON.stringify(this.arr[index]))

Vue.$set


The key code of the

function can be one of the following. If the array subscript is assigned directly, the vue cannot listen for data updates.

      this.arr.splice(index, 1, !this.arr[index])
      this.$set(this.arr, index, !this.arr[index])

this.$set (this.arr,index,ture/false)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36f6d-2c064.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36f6d-2c064.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?