需求:做一个级联选择器,根据每次选中的id去调下一层的接口
<el-cascader size="small" :props="props"></el-cascader>
<script>
let id = 0;
export default {
data() {
return {
props: {
lazy: true,
lazyLoad (node, resolve) {
const { level } = node;
if (!node.data) {
service.getCategory(0).then(res => {
console.log('getCategory', res)
const nodes = Array.from(res).map(item => {
return {
value: item.id,
label: `${item.name}`,
leaf: level >= 1
}
})
resolve(nodes)
})
} else {
service.getCategory(node.data.value).then(res => {
const nodes = Array.from(res).map(item => {
return {
value: item.id,
label: `${item.name}`,
leaf: level >= 1
}
})
resolve(nodes)
})
}
}
}
};
}
};
</script>