問題:當父組件向子組件傳值時,如果改值存在多層數組/對象嵌套,此時改數據變動時,可能造成在子組件中不會重新渲染。
解決方案:如下。
<template>
<new_drawer :key="menuKey" :data='newData'/>
</template>
<script>
export default{
data(){
return {
menuKey:1,
newData:[
{
tital:10,
options:[
{
tital:102
}
]
}
]
}
},
methods:{
menuTree(){
this.newData.forEach((item)=>{
item.options.forEach((item1)=>{
item1.tital=110
})
})
++this.menuKey //newData數據嵌套太深,需要這種方式才能渲染出來改變的newData數據
}
}
}
</script>