做项目的时候遇到这样的需求,很懵,不知道为啥要搞这么复杂。
首先我想到的是不能删除又可以编辑,肯定得需要两个变量来表示,在页面展示又要另一个变量。所以就要用计算属性处理得到的值。保存到数据库中只需要后面输入的详细地址也就是这里的this.afterAddress
fullAddress: {
get: function() {
return this.beforeAddress + " " + this.afterAddress;
},
set: function(newValue) {
console.log("newValue===",newValue);
if (newValue) {
let address = newValue.split(" ");
this.beforeAddress = address[0];
if (address[1]) {
this.afterAddress = address[1];
} else {
this.afterAddress = "";
}
} else {
this.afterAddress = "";
this.handleAddress();
}
},
},
// 处理地址
handleAddress() {
let a = this.provinceData.filter((r) => r.key == this.form.provinceCode);
let b = this.cityData.filter((r) => r.key == this.form.cityCode);
let c = this.areaData.filter((r) => r.key == this.form.placeOfIncorCode);
this.beforeAddress = `${a[0].value}${b[0].value}${c[0].value}`;
},
这里处理有个弊端,两个变量之间需要某个符号或者空格区分一下
网友评论