1
0
Fork 0

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

master
会PS的小码农 4 years ago
parent b7ed96ee4e
commit 7d45f8257c

File diff suppressed because one or more lines are too long

@ -115,12 +115,7 @@ export default {
}; };
}, },
created() { created() {
this.defaultAddr = JSON.parse(JSON.stringify(this.value)); this.init();
this.created = true;
this.checkProvince();
this.checkCity();
this.checkArea();
this.created = false;
}, },
// computed: { // computed: {
// defaultAddr: { // defaultAddr: {
@ -146,13 +141,7 @@ export default {
// }, // },
mounted() { mounted() {
this.$watch("value", (res) => { this.$watch("value", (res) => {
console.log(11); this.init();
this.defaultAddr = JSON.parse(JSON.stringify(this.value));
this.created = true;
this.checkProvince();
this.checkCity();
this.checkArea();
this.created = false;
}); });
}, },
// 姿v-model // 姿v-model
@ -180,6 +169,21 @@ export default {
// }, // },
watch: {}, watch: {},
methods: { 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() { checkProvince() {
this.provinceJson.forEach((element) => { this.provinceJson.forEach((element) => {
@ -193,12 +197,13 @@ export default {
this.defaultAddr.province_code = element.code; this.defaultAddr.province_code = element.code;
this.defaultAddr.province = element.name; this.defaultAddr.province = element.name;
if (!this.created) {
this.$emit("input", this.defaultAddr);
this.defaultAddr.city_code = ""; this.defaultAddr.city_code = "";
this.defaultAddr.area_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_code = element.code;
this.defaultAddr.city = element.name; 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_code = element.code;
this.defaultAddr.area = element.name; this.defaultAddr.area = element.name;
if (!this.created) { // if (!this.created) {
this.$emit("input", this.defaultAddr); // this.$emit("input", this.defaultAddr);
} // }
} }
}); });
}, },

Loading…
Cancel
Save