【发布时间】:2019-07-04 08:35:22
【问题描述】:
我有一个动态组件被注入到另一个组件的插槽中,我将 props 对象传递给它。但是当我更新与道具(dataT: this.tableData)关联的数据(数组)时,该道具不会在组件内更新。
似乎我处理了两个不同的对象,但数组是通过引用传递的,不是吗?
这是主要组件
<template>
<Button @click="addWindows"></Button>
<Window v-for="window in windows" :key="window.id">
<component :is="window.name" v-bind="window.props" @onDeleteRow="handleDeleteRow"></component>
</Window>
</template>
<script>
export default{
data(){
return{
windows:[],
tableData:[
{
id: '0',
name: 'dog'
},
{
id: '1',
name: 'cow'
},
{
id: '2',
name: 'cat'
}
]
}
},
methods:{
addWindows(){
this.windows = [
{
id: 0,
name: 'Component1',
props: {
dataT: this.tableData
}
},
{
id: 1,
name: 'Component2',
props: {}
}];
},
handleDeleteRow(id){
this.tableData = this.tableData.filter(r => r.id != id);
}
}
}
</script>
当我在主组件中修改this.tableData 时,我希望更新Component1 中的dataT 属性。
【问题讨论】:
标签: javascript vue.js vue-component