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

Created on 21 Sep 2020  ·  1Comment  ·  Source: ElemeFE/element

Element UI version

2.13.2

OS/Browsers version

Mac/Chrome 84.0.4147.105

Vue version

2.6.11

Reproduction Link

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是可以的

Most helpful comment

是将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 = []

>All comments

是将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 = []
Was this page helpful?
0 / 5 - 0 ratings