公司要求在pc端做一个选择门店下员工的功能,我使用到了element-plus的级联选择器,接口有两个,分为门店接口和根据门店查员工接口,接着出现了无论点哪一级的数据都不触发change事件的问题
进入页面时加载第一级的数据,这里返回结果的参数名称分别是shopName,posid
给el-cascader的props如下:
monitorProps: {
label: 'shopname',
value: 'posid',
checkStrictly: props.checkStrictly,
multiple: props.multiple,
emitPath: true,
lazy: true,
lazyLoad(node, resolve) {
const { level } = node
console.log(node.value)
if (level && node.value) {
getfollowerlist({ posid: node.value }).then((res) => {
resolve(res.data)
})
}
},
},
点击门店后请求第二级也就是员工的数据,返回的字段名有value
由于我设置的props的value有问题,二级菜单并没有posid,所以导致了change事件不触发,解决方法是两层结构需要同样的字段名,这个字段的数据也是最终想要拿到的数据,最终改成了:
monitorProps: {
label: 'shopname',
value: 'posid',
checkStrictly: props.checkStrictly,
multiple: props.multiple,
emitPath: true,
lazy: true,
lazyLoad(node, resolve) {
const { level } = node
console.log(node.value)
if (level && node.value) {
getfollowerlist({ posid: node.value }).then((res) => {
const temp = res.data
temp.map((item) => {
item.posid = item.value
item.leaf = true
})
resolve(res.data)
})
}
},
},