您好,欢迎来到百家汽车网。
搜索
您的当前位置:首页elementuicascader级联选择器动态加载以及回显

elementuicascader级联选择器动态加载以及回显

来源:百家汽车网
elementuicascader级联选择器动态加载以及回显

在⽤实际开发时使⽤遇到通过点击⼀级的下拉选项去动态获取⼆级下拉选项.以此记录:使⽤:

定义变量以及设置:

data() { return {

doctorValue:[] props: {

//checkStrictly: true,// ⽗⼦节点是否互相关联,其余配置见官⽹ lazy: true,

lazyLoad: this.lazyLoad } }; },

点击动态加载:

lazyLoad(node, resolve) { setTimeout(() => {

this.getHospital(node, resolve) }, 50) },

getHospital(node, resolve) { // 第⼀级

     // this.hospitalData 是提前接⼝获取的⼀级下拉框

if (node.level == 0) {

const nodess =this.hospitalData.map((i, index) => ({ value: i.id,

label: i.hospitalName, }))

resolve(nodess); }

// 第⼆级

if (node.level == 1) { let data = {

hospitalId: node.data.value, sortType: \"default\" };

getDoctorsByHospital(data).then(res => { // console.log(res)

const nodes = res.data.map((item, index) => ({ value: item.id,

label: item.doctorName, leaf: node.level >= 1

         // 节点数,我的只有⼆级,设置之后点击⼆级不再出现加载圈 }));

resolve(nodes); }) } },

第⼆次进来以后,并不能正确回显,查询资料后,在会显⽰时,重新渲染级联选择器的⽅法最简单

this.doctorValue = [res.data.hospitalId, res.data.doctorId]this.showSelect = falsesetTimeout(() => {

this.showSelect = true }, 50)

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baijiahaobaidu.com 版权所有 湘ICP备2023023988号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务