- cascader重新懒加载Cannot read propert
- 解决TypeError: Cannot read propert
- 报错TypeError: Cannot read propert
- [vue-router] Cannot read propert
- vue echart报错:Cannot read propert
- Cannot read property 'length' of
- elementui Cascader懒加载
- vue用axios时报错:Cannot read propert
- vue用axios时报错:Cannot read propert
- cannot be found on object of typ

场景问题步骤
- 当
cascader
采用懒加载方式加载子菜单 -
cascader
选中一次子节点 - 重置选中值
v-model
为默认值[]
- 重置选项
options
为默认值[]
此时出现报错:

分析报错原因
- 根据报错代码位置一步步锁定到
node_modules/element ui/lib/element-ui.common.js
中的

- 这里本应该是个空数组,然后
cascader
的选中值v-model
在传递过程当中,watch
到value
变化耗时比较长,所以导致场景问题步骤中3操作穿插在重新获取第一层选项的的代码执行过程中,以至于读取到value的值为一个包含null
值的数组

解决方案
已经知道问题所在,那就好办了,只要我们在重置完选中值之后用nextTick()
来调用重置选项,就可以保证value值全部更新再获取新选项了
this.$refs.category_id.resetField()//重置选中值
this.$nextTick(() => {
this.categoryIdOptions = []////重置选项
})
如果你觉得这篇文章有解决你的问题,那就buy me a coffee
,然后小编就会很有动力的哦
(二维码没了扎心)
网友评论