The binding value of vue about the value of class is an object problem.

<div v-for="(item, index) in list" :class="["a", selectItem[0][index]==1?"b":"c"]" @click="changeSelectItem(0,index)"></div>
<div v-for="(item, index) in list" :class="["a", selectItem[0][index]==1?"b":"c"]" @click="changeSelectItem(1,index)"></div>
data:{
 list:[]
 selectItem = {
  0:[0,0,0],
  1:[0,0,0]
 } 
}
methods: {
  changeSelectItem(key,index){
    this.selectItem[key][index]=1
  }
},
created () {
  this.List = XXX//
}

vue"s foundation is weak, not very clear about its internal mechanism, when writing the code, (the whole code is about the above), found that when I call the changeSelectItem function to change the array in the selectItem object, class will not change dynamically, it is not clear whether the class binding can not be as deep as my needs in the array to bind, if not, can only manually add the class name for the dom element, looking for a big solution!

Apr.26,2021

the logic is fine, and the invalid reason is that this.selectItem [key] [index] = 1 this assignment method cannot be monitored by vue. See the document 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 "> vue array update detection

for specific reasons and solutions.

Test address


  1. it is recommended to use calculation properties;
  2. data is not dynamic and needs to be monitored.

because vue cannot responsively assign an attribute value that the data object does not have, my selectemItem was originally an empty object, so forget it. Thank you for your answers.

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-1b30354-2bced.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-1b30354-2bced.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?