mpvue小程序突然數(shù)據(jù)更新,視圖不更新!

我們公司小程序用的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太痛苦了!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容