我們公司小程序用的mpvue寫的,已經(jīng)上線使用一年了!!但就在前幾天,突然小程序所有的多選框都失效了;console了下數(shù)據(jù),但數(shù)據(jù)是在實(shí)時(shí)更新的?。。〉前?,點(diǎn)擊后數(shù)據(jù)變了但視圖就是不更新!這就很奇怪了。翻看了好幾遍的vue的響應(yīng)式原理,也還是不管用!
總結(jié)一下,這次煩躁修bug的過程。希望能幫到遇見同樣問題的程序媛們!
頁面選擇框的布局:
<div class="group" v-for="(item, index1) in eventDate.enrollListObj" :key="index1">
<div class="item" v-for="(block, index3) in item.block" :class="{'hide': noSize && !block.checked}" @click="selectBlock(index1, index3, item.groupNum)" :key="index3">
<div class="block" :class="block.checked ? 'checked': ''">
<img :src="blockIcon[block.checked]"/>
</div>
<div class="name one-line">{{block.checked ? '已選擇':'點(diǎn)擊選擇'}}</div>
</div>
</div>
點(diǎn)擊事件的方法, 用的 $set 來更改新添加屬性的值,還用了強(qiáng)制刷新!添加的屬性也有g(shù)et和set的!但還是沒有反應(yīng)??
selectBlock (index, subIndex, groupNum) {
const page = this
page.$set(page.eventDate.enrollListObj[index].block[subIndex], 'checked', !page.eventDate.enrollListObj[index].block[subIndex].checked)
page.$forceUpdate()
}
直到今天下午,我想到是不是還是需要監(jiān)控屬性一下呢?于是我嘗試了:
computed: {
newEnrollListObj () {
return this.eventDate.enrollListObj
}
}
那么布局循環(huán)的列表數(shù)據(jù)也要改一下:
<div class="group" v-for="(item, index1) in newEnrollListObj" :key="index1">
重新運(yùn)行就可以啦?。。?!這種突如其來的bug太痛苦了!