(Avue)
1、问题
v-region 地址组件无法回显(选择地址保存后,打开编辑,发现刚才选择的地址【省市县乡】信息消失,信息不回显)
选择好省市县乡后,保存,再次编辑,发现如下:
2、解决方案:初始化 地址
参考资料:https://terryz.gitee.io/vue/#/region/demo
① 在前台修改
<avue-crud :data="data"
:before-open="beforeOpen"
>
在v-region里面加入 v-model属性
<template slot="addressForm">
<v-region :town="true" type="group" @values="selectAddress" v-model="addressSelected">
</v-region>
</template>
②
data() {
return {
addressSelected: {}
}
}
methods: {
//编辑前加载,回显
beforeOpen(done, type) {
this.addressSelected.province = this.obj.addrProvinceKey
this.addressSelected.city = this.obj.addrCityKey
this.addressSelected.area = this.obj.addrCountyKey
this.addressSelected.town = this.obj.addrTownKey
done()
},
selectAddress(values) {
//显示到表格地址栏
this.obj.addrProvince = values.province && values.province.value
this.obj.addrCity = values.city && values.city.value
this.obj.addrCounty = values.area && values.area.value
this.obj.addrTown = values.town && values.town.value
//回显
this.obj.addrProvinceKey = values.province && values.province.key
this.obj.addrCityKey = values.city && values.city.key
this.obj.addrCountyKey = values.area && values.area.key
this.obj.addrTownKey = values.town && values.town.key
}
③在后台修改
找到该实体类,添加 【省市县乡编码】字段(如 addrProvince······)
④数据库修改
加【省市县乡编码】列(如 addrProvince······)