省市区你又来辣!!!+发送搜索条件判空处理
0. 缘起
today, afraid by 省市区!!!
出现了1个阴间问题,只要我改了省,之后的市和区就无法选中!!!原因就是我watch省,省改变就把市区都变成'',但初始化的时候没有初始化这三个,所以就出现了很阴间的情况!!!
1. 关键
this.form = {
industryType: "",
industryTypeMedium: "",
industryTypeLimit: "",
regionProv: "",
regionCity: "",
regionArea: "",
}
这部分很关键,如果不初始化,就会出现上述的阴间情况!!!
2. 发送时进行判空处理
searchTable() {
// Important
let form = {},
self = this;
Object.keys(this.form).forEach((key) => {
if (!isEmpty(key)) {
form[key] = this.form[key];
}
});
// RegionAncestors Special
if ((form.regionProv ?? "") !== "") {
form.regionAncestors = getAddress();
}
this.$emit("deliver-search", form);
function isEmpty(keyName) {
return self.form[keyName] === "";
}
function getAddress() {
let prov = form?.regionProv;
let city = form?.regionCity;
let area = form?.regionArea;
let str = ",";
if ((area ?? "") !== "") {
return prov + str + city + str + area;
} else {
if ((city ?? "") !== "") {
return prov + str + city;
} else {
if ((prov ?? "") !== "") {
return prov;
} else {
return "";
}
}
}
}
},
人生到处知何似,应似飞鸿踏雪泥。