element-ui cascader 省市区 动态加载

缺点:不能赋默认值(目前还没找到方法 )
解决:原来是返回的默认值和请求的数据类型不一样(code) 如果数据类型一样是可以回显默认值的

props:设置赋值规则

2020/3/3新增数据格式
[
    {
       code: 省编码,
       name: "省名",
       cities:[
          {
             code: 市编码,
             name: "市名",
             cities:[
                {
                  code: 区编码,
                  name: "区名",
                }
              ]
          }
       ]
    },
    {
      code: "140000",
      name: "山西省",
      cities: [
        {
           code: "140400",
           name: "长治区",
           cities:[
                {
                  code: "140421",
                  name: "长治县"
                }
              ]
          },
      ]
  }
  
    ...
]

data(){
return{
      address:[],
      options: [],
      props: {
        label: "name",
        value: "code",
        children: "cities",
        lazy: true,
        lazyLoad(node, resolve) {
          const { level } = node;
          getProvinces({ code: node.value }).then(res => {
            if (res.code == 200) {
              res.data.forEach(el => {
                el.leaf = level >= 2;
              });
              resolve(res.data);
            }
          });
        }
      },
}
}
1565941573(1).png

你可能感兴趣的:(element-ui cascader 省市区 动态加载)