可以不用监听父组件的传值,这里监听只是为了方便修改showIf的值,避免修改父组件传过来的布尔值。
主要是将v-model的值设置为对象即可
//----------------------------子组件
// 子组件,需要通过父组件传过来的showIf进行是否显示组件
<van-action-sheet
v-model="showIf"
/>
props: {
showEdit: {
type: Object,
default: () => {
return {
type: false
};
}
},
},
watch: {
showEdit: {
deep: true,
handler(val) {
this.showIf = val.type;
}
},
}
//----------------------------父组件
<create-or-edit
:showEdit="showEdit"
ref="createOrEdit"
></create-or-edit>
click() {
this.showEdit = {
type: false
};
}