vant省市区三级联动⾃定义json数据展⽰取值{"code":"110000","name":"北京市"}
{"code":"110100","name":"北京市","parent_code":"110000"}
{"code":"110101","name":"东城区","parent_code":"110100"}
j son⽂件中的省市区都是这种格式
⽽vant 的组件规定这种格式
我将json数据拼接字符串完成页⾯效果
created() {
//导⼊json ⽂件
let provinces = require("../../static/json/provinces.json");
let cities = require("../../static/json/cities.json");
let areas = require("../../static/json/areas.json");
//拼接省
let str = "{";
provinces.forEach((item) => {
str = str + '"' + de + '"' + ":" + '"' + item.name + '"' + ",";
internet});
let provinceStr = str.substring(0, str.length - 1) + "}";
let province = JSON.par(provinceStr);
8年级语文//拼接市
let str1 = "{";
cities.forEach((item) => {
str1 = str1 + '"' + de + '"' + ":" + '"' + item.name + '"' + ",";
});
let citiesStr = str1.substring(0, str1.length - 1) + "}";
let city = JSON.par(citiesStr);
//拼接区
let str2 = "{";
areas.forEach((item) => {
resultingstr2 = str2 + '"' + de + '"' + ":" + '"' + item.name + '"' + ",";
});
let areasStr = str2.substring(0, str2.length - 1) + "}";牛奶煮饭
let areas = JSON.par(areasStr);
//最后将值赋给对象
this.areaList.province_list = province;
英文专业翻译this.areaList.city_list = city;
unty_list = areas;
console.log(this.areaList);
},
小孩子英语这样页⾯就展⽰出来了
取值通过它⾃带的⽅法
师心自用的意思onConfirm(values) {
this.value = values.map((item) => item.name).join("/");
console.log(values[0].code);
console.log(values[1].code);
console.log(values[2].code);
this.showArea = fal;
},
打印出来对应的code儿童睡前故事
好了,这样就实现了。当时真的好烧脑,多亏我同事帮助,⾮常感谢。希望本篇⽂章能帮到你。我是⾦陵彭于晏我们下期再见!