vue 父组件通过ref调用子组件方法 更新数据后,视图部更新
而在子组件mounted(){}里调用统一方法可以更新
vue版本2.5.15
parent.vue
this.$nextTick(() => {
this.$refs.carInfo.getDetail(data)
})
child.vue
data () {
return {
imgUrl: '',
plate_number: '',
car_detail: {
serial_number: '',
plate_type: '',
china_brand: '',
model: '',
car_type: '',
color: '',
use_for: '',
inspection_date: ''
},
car_owner: {
name: '',
identification_number: '',
quasi_drive_type: '',
expire_date: '',
cumulative_score: '',
license_status: ''
},
}
},
methods: {
getetail(){
this.obj = res.content // 这里父组件$refs.name.getDetail()调用时控制台数据改变但是视图没变
}
},
beforeUpdate () {
console.log('before update', this.$data)
},
updated () {
console.log('update', this.$data)
},
mounted(){
// setTimeout(() => { 这里调用可以更新视图
// this.getDetail()
// }, 3000)
}
用Vue.$set(...), 也不起作用
这段代码,在什么时候被调用的呢?