vue+antd <a-cascader />级联选择
报错原因:
this.options = res.data
尤为层级children里有的是null,才导致报这个警告。
修改为:
this.options = this.formatData(res.data)
//格式化数据,递归将空的children置为undefined
formatData(data) {
const that = this
data.forEach((element) => {
if (element.children && element.children.length > 0) {
that.formatData(element.children)
} else {
element.children = undefined
}
})
return data
},
本文探讨了在使用Vue与Ant Design的级联选择组件时,如何处理因API返回数据中存在null导致的警告,并通过formatData方法递归转换数据结构,确保组件正常工作。


1593

被折叠的 条评论
为什么被折叠?



