element-ui cascader 省市区 动态加载

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

props:设置赋值规则

数据格式
[
    {
       code: 省编码,
       name: "省名",
       cities:[
          {
             code: 市编码,
             name: "市名",
             cities:[
                {
                  code: 区编码,
                  name: "区名",
                }
              ]
          }
       ]
    },
    {
      code: "140000",
      name: "山西省",
      cities: [
        {
           code: "140400",
           name: "长治区",
           cities:[
                {
                  code: "140421",
                  name: "长治县"
                }
              ]
          },
      ]
  }
  
    ...
]
<el-cascader
  v-model="address"
 :options="options"
 :props="props"
 separator="-"
></el-cascader>
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);
            }
          });
        }
      },
}
}
 
posted @ 2020-04-23 15:49  biggaio064  阅读(1149)  评论(0编辑  收藏  举报