HTML
<el-cascader :props="props"></el-cascader>
data
props:{
lazy:true,
lazyLoad:this.lazyLoad
}
methods
先请求第一个节点接口的数据 在根据第一个节点的数据当做参数请求第二个节点的接口数据
lazyLoad (node,resolve) {
this.getData(node,resolve)
},
async getData (node,resolve) {
let level = node.level
if(!node.data) {
let res = await services.material.warehouseInfo({params:1})
const nodes = Array.from(res.data).map(item=>({
value:item.warehouseCode,
label:item.warehouseName,
leaf: level >= 1
}))
resolve(nodes)
}else{
let res = await services.material.warehouseAreaList({params:1,warehouseCode:node.data.value})
const nodes = Array.from(res.data).map(item=>({
value:item.areaCode,
label:item.areaName,
leaf: level >= 1
}))
resolve(nodes)
}
}