Use v-for to traverse N follow buttons, click one of the follow buttons, and the corresponding follow button becomes followed. This is the first time
<img v-if='flag' @click='change()' :src='countries[num]' alt="">//关注
<img v-if='!flag' :src='countriesHasAttention[num]' alt="">// 已关注
data () {
return {
flag: true
}
}
change: function () {
this.flag = false
}
I found that clicking one changed everything, and then I changed the flag to an array
<img v-if='flag[index]' @click='change(index)' :src='countries[num]' alt=""> //关注
<img v-if='!flag[index]' :src='countriesHasAttention[num]' alt=""> // 已关注
data () {
return {
flag: [true, true, true]
}
}
change: function (index) {
this.flag[index] = false
}
发现这样做点击的时候按钮不发生变化。
求大神指导一下
The
change part is changed to
Vue.set
The template can be simplified like this:
The answer above for data processing is correct, see: Array Update Detection