:load-data="loadData"指:从后端查询出的全部的省市区数据
loadData(item, callback) {
item.loading = true
if (item.flag === 0) {
let url = '/listCityByProvinceCode'
this.$get(
url,
{ provinceCode: item.value },
(res) => {
let result = res.data
if (result.status == 200) {
let data = result.data
for (let i in data) {
let city = {}
city.label = data[i].cityName
city.value = data[i].cityCode
city.flag = 1
if (item.value != '820000') {
city.children = []
city.loading = false
}
item.children.push(city)
}
callback()
item.loading = false
} else {
this.$toast(result.msg)
}
},
(err) => {
this.$hideMark()
this.$toast(this.networkerr)
item.loading = false
}
)
}
if (item.flag === 1) {
let url = '/listAreaByCityCode'
this.$get(
url,
{ cityCode: item.value },
(res) => {
let result = res.data
if (result.status == 200) {
let data = result.data
for (let i in data) {
let city = {}
city.label = data[i].areaName
city.value = data[i].areaCode
// city.children = [];
// city.loading = false;
city.flag = 2
item.children.push(city)
}
callback()
item.loading = false
} else {
this.$toast(result.msg)
}
},
(err) => {
this.$hideMark()
this.$toast(this.networkerr)
item.loading = false
}
)
}
},
:data="cityData"指:
cityData=[],
//获取省份列表
listProvince() {
let url = ‘/listProvince’
this.KaTeX parse error: Expected '}', got 'EOF' at end of input: … this.toast(result.msg)
}
},
(err) => {
this.
h
i
d
e
M
a
r
k
(
)
t
h
i
s
.
hideMark() this.
hideMark()this.toast(this.networkerr)
}
)
},
@on-change=“cityChange”:选择省市区这个动作
cityChange(value, selectedData) {
//let regionId=this.formValidate.regionFlag;
this.provinceCodeId = selectedData[0].value
console.log(selectedData)
console.log(selectedData[0].value)
console.log(selectedData.length)
//this.formValidate.cityData2=selectedData;
this.cityMsg = ''
if (selectedData != null && selectedData.length > 0) {
for (let i in selectedData) {
if (i == 0) {
this.formData.province = selectedData[0].value
}
if (i == 1) {
this.formData.city = selectedData[1].value
}
if (i == 2) {
this.formData.area = selectedData[2].value
}
}
}
},
v-model=“formData.cityData2”:选择好绑定的省市区参数
<Row :gutter="16">
<Col span="12">
<FormItem label="省/市/区" prop="cityData2">
<Cascader
:data="cityData"
v-model="formData.cityData2"
@on-change="cityChange"
filterable
:clearable=false
:load-data="loadData"
></Cascader>
</FormItem>
</Col>
</Row>