element-ui中的懒加载级联选择

<el-cascader
     ref="cascader"
     :options="options"//数据
     //lazy懒加载,lazyLoad是懒加载的方法,checkStrictly单选的按钮
     :props="{lazy:true,lazyLoad:loadOptions, checkStrictly: true }"
     size="small"
     v-model="cascadrValue"
     @change="handleChange"//单选按钮的选择事件
/>

<script>
  export default {
    data() {
      return {
         options:[],
         cascadrValue:"",
         treeIndex:"",
      };
    },
    methods:{
       loadOptions (node, resolve) {
        if (node.level === 0) {
          return resolve(数据列表);
        }
        if (node.level > 9999) return resolve([]);//可以选择到第几层
        // 判断isLoading变量值,避免重复请求和无效请求
        if (!this.isLoading && node.data.id) {
          this.isLoading = true;
          setTimeout(() => {
            const params = {
             //参数
            };
            this.nodeId = node.data.id;
            getTreeDataList(params)
              .then((data) => {
                if (data.result === true) {
                  const items = [];
                  接口的数据.forEach(function (obj) {
                    items.push({
                      label: obj.name,
                      id: obj.id,
                      value: obj.name,
                    });
                  });
                  resolve(items);
                  //调用渲染数据的方法,重新在这块调用
                  this.isLoading = false;
                }
                else {
                  this.$message({
                    type: `warning`,
                    message: `获取信息出错`,
                  });
                }
              })
              .catch(() => {
                this.isLoading = false;
              });
          }, 500);
        }
        else {
          resolve([]);
        }
      },
      handleChange () {
        let nodeObj = [];
        this.$nextTick(() => {
          nodeObj = this.$refs[`cascader`].getCheckedNodes(true);
          console.log(nodeObj,"nodeObj");
          const p = this.treeIndex = nodeObj.map((param) => {
            this.nodeId = 拿id;
            return 这块return也是放id;
          }).join(`,`);
        })
        在这块重新调用那个数据列表渲染的方法
      },
    }
  };
</script>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值