element [Bug Report] el-cascader 在@change中修改v-model绑定的值,会报Cannot read property 'level' of null

thigvfpy  于 2022-12-31  发布在  其他
关注(0)|答案(2)|浏览(426)

Element UI version

2.13.2

OS/Browsers version

Mac/Chrome 84.0.4147.105

Vue version

2.6.11

https://codepen.io/thj2/pen/yLOerdR

Steps to reproduce

1.点击全部
2.点击其他选项就会报错
3.不能删除

What is Expected?

修改 element-ui->lib->casader-panel.js 下
handleExpand: function handleExpand(node, silent) {}
在此方法中判断node是否为空

if(!node)return

不知道什么原因我在@chang方法中二次修改后node为空

在1294行 var nodes = activePath.map(function (node) {
return _this2.getNodeByValue(node.getValue());
});
nodes为 []导致后面的错误

What is actually happening?

统一报错(TypeError: Cannot read property 'level' of null)
版本element-ui 2.10.0是可以的

iecba09b

iecba09b1#

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jdzmm42g

jdzmm42g2#

是将options清空导致的。
里面有bug,options清空后,activePath没有清空,内部使用activePath去查找就会找不到成为null导致。
将options清空前先执行

// 假设cascader的options变量为this.options,绑定v-mode变量为select ref为cascader

// 先清除选中项和激活的项
this.$refs.cascader.$refs.panel.clearCheckedNodes()   // 清除选中项
this.$refs.cascader.$refs.panel.activePath = []              //  清除激活的菜单
// 再清空选项或赋值新的选项
this.select = []
this.options = []

相关问题