cascader 搜索踩坑记录
[Vue warn]: Error in render: “TypeError: Cannot read properties of undefined (reading ‘toLowerCase’)”
TypeError: Cannot read properties of undefined (reading ‘toLowerCase’)
报这个错误,解决问题的关键点在这里,官网用的是
但是我用了这个 :fieldNames="{ label: ‘text’, value: ‘id’, children: ‘children’ }",所以label应该换成
text,完美解决!
实现效果:
部分正确代码:
<a-form-item label="所属部门" :label-col="{ span: 3 }" :wrapper-col="{ span: 21 }">
<a-cascader
:fieldNames="{ label: 'text', value: 'id', children: 'children' }"
v-decorator="['Dept']"
placeholder="请选择所属部门"
:options="deptTreeData"
change-on-select
:show-search="{filter}"
:getPopupContainer="(triggerNode) => triggerNode.parentNode"
/>
</a-form-item>
//所属部门搜索
filter(inputValue, path) {
console.log(path)
return path.some(option => option.text.toLowerCase().indexOf(inputValue.toLowerCase()) > -1)
},