今天剛剛 解決了一個問題 先大概簡單說一下,后期詳細(xì)說
比如vue中 數(shù)據(jù)和DOM 雙向綁定 ,數(shù)據(jù)的改變會讓 dom重新渲染。
但是如果是 層級比較深的 json 對象格式的 數(shù)據(jù) 深層次的 改變 并不會 導(dǎo)致dom重新渲染。
所以會比較 著急。
今天 我作一個 二維數(shù)組 的層級 條件 顯然的時候 遇到了這樣一個問題。用戶點(diǎn)擊操作正確。雙向綁定的數(shù)據(jù)也改變了。。但是就是反應(yīng)不到 dom上 ,
這是這時候 我的解決辦法是 讓 層級深入 的數(shù)據(jù)改變 -> 觸發(fā) 第一層的數(shù)據(jù)改變 vue可以容易的檢測到 收測數(shù)據(jù)改變 然后重新 根據(jù)數(shù)據(jù) 渲染dom 。從而決絕這個歌問題。

image.png
//判斷是否顯示
addItemIsShow() {
let that =this;
var l=this.qnaire.allQuestions.length;
for (let i = 0; i < this.qnaire.allQuestions.length; i++) {
for (let m = 0; m < this.qnaire.allQuestions[i].length; m++) {
this.domRander=true;
this.qnaire.allQuestions[i][m].isShow=false;
if(this.qnaire.allQuestions[i][m].hasOwnProperty('deps')){
let strArr = this.qnaire.allQuestions[i][m].deps[0].split('/');
if(this.qnaire.allQuestions[i][m].category==2&&this.ansObj[strArr[0]].includes(strArr[1])){
this.qnaire.allQuestions[i][m].isShow=true;
}
if(this.ansObj[strArr[0]]==strArr[1]){
this.qnaire.allQuestions[i][m].isShow=true;
}
}else{
this.qnaire.allQuestions[i][m].isShow=true;
}
}
this.domRander=false;
}
},