调整外部数据更新后插件内自动同步相关

This commit is contained in:
2022-04-07 20:07:23 +08:00
parent b7ed96ee4e
commit 7d45f8257c
2 changed files with 35 additions and 28 deletions
+2 -2
View File
File diff suppressed because one or more lines are too long
+33 -26
View File
@@ -115,12 +115,7 @@ export default {
};
},
created() {
this.defaultAddr = JSON.parse(JSON.stringify(this.value));
this.created = true;
this.checkProvince();
this.checkCity();
this.checkArea();
this.created = false;
this.init();
},
// computed: {
// defaultAddr: {
@@ -146,13 +141,7 @@ export default {
// },
mounted() {
this.$watch("value", (res) => {
console.log(11);
this.defaultAddr = JSON.parse(JSON.stringify(this.value));
this.created = true;
this.checkProvince();
this.checkCity();
this.checkArea();
this.created = false;
this.init();
});
},
// 不知道是哪里姿势不对用了此方法就一直无法获取父主键传过来的v-model
@@ -180,6 +169,21 @@ export default {
// },
watch: {},
methods: {
init() {
let newAddress = JSON.stringify(this.value);
let oldAddress = JSON.stringify(this.defaultAddr);
console.log(newAddress.toString(), oldAddress.toString());
if (newAddress.toString() != oldAddress.toString()) {
this.defaultAddr = JSON.parse(newAddress);
console.log(1111);
this.checkProvince();
this.checkCity();
this.checkArea();
this.$emit("input", this.defaultAddr);
}
},
// 选择省
checkProvince() {
this.provinceJson.forEach((element) => {
@@ -193,12 +197,13 @@ export default {
this.defaultAddr.province_code = element.code;
this.defaultAddr.province = element.name;
if (!this.created) {
this.$emit("input", this.defaultAddr);
this.defaultAddr.city_code = "";
this.defaultAddr.area_code = "";
}
this.defaultAddr.city_code = "";
this.defaultAddr.area_code = "";
// if (!this.created) {
// this.$emit("input", this.defaultAddr);
// this.defaultAddr.city_code = "";
// this.defaultAddr.area_code = "";
// }
}
});
},
@@ -214,10 +219,12 @@ export default {
this.defaultAddr.city_code = element.code;
this.defaultAddr.city = element.name;
if (!this.created) {
this.$emit("input", this.defaultAddr);
this.defaultAddr.area_code = "";
}
this.defaultAddr.area_code = "";
// if (!this.created) {
// this.$emit("input", this.defaultAddr);
// this.defaultAddr.area_code = "";
// }
}
});
},
@@ -232,9 +239,9 @@ export default {
) {
this.defaultAddr.area_code = element.code;
this.defaultAddr.area = element.name;
if (!this.created) {
this.$emit("input", this.defaultAddr);
}
// if (!this.created) {
// this.$emit("input", this.defaultAddr);
// }
}
});
},