1.只需要在子组件的watch监听方法基础上,启动uniapp封装后的this.$watch方法使用深度监听。
具体方法看下面的create();
XXX为你父组件传递的对象;
使用后,再监听对象里的属性就不会返回空了。
<template>
<div>
<p>{{ XXX }}</p>
<button @click="changeMessage">Change Message</button>
</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello, world!'
}
},
created() {
this.$watch('XXX', (newValue, oldValue) => {
console.log('XXX changed:', newValue)
// 在这里可以执行你想要的操作
}, { deep: true })
},
methods: {
changeMessage() {
this.XXX= 'New XXX'
}
}
}
</script>
父子组件的数据传递请翻看过往文章。