鍍金池/ 問答/HTML/ vue深度拷貝后怎樣觀察得到的新數(shù)組或?qū)ο螅?/span>

vue深度拷貝后怎樣觀察得到的新數(shù)組或?qū)ο螅?/h1>

在data中定義了一個空數(shù)組multiclewcontent,在拿到數(shù)據(jù)后對數(shù)據(jù)進行遍歷,數(shù)據(jù)的長度就是multiclewcontent的長度。

this.multiclewcontent[i] = JSON.parse(JSON.stringify(this.arr));

最后得到下面的一個數(shù)組
圖片描述

可以看到里面的元素vue已經(jīng)不能觀察到了,請問這個問題怎么解決?

回答
編輯回答
別瞎鬧
// 使用Vue.set
Vue.set(this.multiclewcontent, i, JSON.parse(JSON.stringify(this.arr)))

// 使用變異方法
this.multiclewcontent.push(JSON.parse(JSON.stringify(this.arr)))
2018年4月6日 11:35