<u-picker
keyName="name"
:show="show"
@cancel="show=false"
ref="uPicker"
class="uPicker"
:columns="columns"
@confirm="confirm"
@change="changeHandler"
:defaultIndex="defaultarr"
>
</u-picker>
import sheng from "@/static/common/js/sheng.js"
import shi from "@/static/common/js/shi.js"
import qu from "@/static/common/js/qu.js"
changeHandler(e) { //监听联动的操作
const {
columnIndex,
value,
values, // values为当前变化列的数组内容
indexs,
picker = this.$refs.uPicker
} = e
console.log(value)
console.log(values)
console.log(e)
console.log(indexs)
if (columnIndex === 0) {
// picker为选择器this实例,变化第二列对应的选项
// 注释 获取城市要有下标
// 而 一个对象的字符串 例:const aa ="1":[{name:"222"}]
// 获取需要 aaa["1"]对应 所以需要下面这样写
// console.log(this.shi[value[0].code][indexs[1]].code)
// console.log(this.shi[value[0].code][indexs[1]].code)
picker.setColumnValues(1, this.shi[value[0].code])
picker.setColumnValues(2,this.qu[this.shi[value[0].code][0].code])
}
if (columnIndex === 1) {
console.log(this.qu[this.shi[value[0].code][0].code])
picker.setColumnValues(2,this.qu[this.shi[value[0].code][indexs[1]].code])
}
},
省市区地址json文件:https://gitee.com/gaohuazi/china_regions?_from=gitee_search