cityComponents
是子组件,cityId
是父组件传给子组件的值,getData
是子组件的渲染数据方法
一:在父组件中用ref=“com” 来声明组件,然后通过this.$refs.str.method()
在值改变的地方来调用子组件中的方法来重新渲染,一定要写Vue.nextTick( [callback, context] )
子组件this.$emit('checkcity', row)
父组件
checkcity(row) {
this.cityId = row.id
// DOM 更新后
this.$nextTick(() => {
this.$refs.cityComponents.getData()
})
}
二:子组件用watch监听数据变化,重新渲染,更推荐这个方法
watch: {
cityId: {
immediate: true, // 这句重要
handler(val) {
this.getData()
},
},
}