1. 使用prop传值:
export default { props: { data: { default:()=> { return {} }, type: Object } } }
2. watch使用:
watch: {
data: {
handler (n) {
// 关闭组件时初始化
if (n.show) {
// 初始化
this.loop_details = [{
control: '1/4',
max: 4
}]
this.longLat = {
show: false,
lnglat: '',
c_lnglat: '',
}
if (this.$refs["modalForm"]) {
this.$refs["modalForm"].resetFields();
}
// 赋值
this.dialogData = JSON.parse(JSON.stringify(n))
if (!this.dialogData.formData.logic_address) {
this.dialogData.formData.logic_address = '1/1' //逻辑控制器默认地址未1/1
}
if (this.dialogData.formData.loop_details) {
let arr = this.dialogData.formData.loop_details
this.loop_details = []
arr.forEach(item => {
this.pushLoop(Number(item.loop_numbers))
});
}
// 经纬度重组
if (n.formData.latitude) {
this.dialogData.formData.lnglat = this.longLat.c_lnglat = n.formData.longitude + ',' + n.formData.latitude
}
this.dialogData = JSON.parse(JSON.stringify(this.dialogData))
}
},
deep: true,
immediate: true
}
},