问题:当父组件向子组件传值时,如果改值存在多层数组/对象嵌套,此时改数据变动时,可能造成在子组件中不会重新渲染。
解决方案:如下。
<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>