父组件向子组件传基本数据类型值(Number、String、布尔值等),父组件传入的值刷新改变时,子组件可以接收得到。
父组件向子组件传引用类型值( Object、Array等),父组件传入的值刷新改变时,子组件接收不到改变。这时需要使用watch进行监听。
// 子组件接收值
props: {
geoValue: {
type: Object,
default: () => {
return {}
}
}
},
// 监听该值,不为空时,在调用方法
watch: {
geoValue: {
handler(val) {
this.geoValue = val
this.$nextTick(() => {
if(this.geoValue.length !== 0){
this.getChinaOption()
}
})
},
deep: true,
immediate: true
}
}