element-ui 报错Cannot read property 'setCheckedKeys' of undefined"
[Vue warn]: Error in event handler for "click": "TypeError: Cannot read property 'setCheckedKeys' of undefined"这个错误是因为你的dom元素还没有加载完,你就想使用 setCheckedKeys 设置目前勾选的节点。也就是你写的this.$refs.
[Vue warn]: Error in event handler for "click": "TypeError: Cannot read property 'setCheckedKeys' of undefined"
这个错误是因为你的dom元素还没有加载完,你就想使用 setCheckedKeys 设置目前勾选的节点。也就是你写的this.$refs.tree.setCheckedKeys(list); 这个里面的 tree 还没有加载出来。
解决方案:
this.$nextTick(() => {
this.$refs.tree.setCheckedKeys(list)
});
(1)Vue.nextTick([callback, context]) 查看 vueJs 官网
用法:在下次 DOM 更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法,获取更新后的 DOM。
(2)vm.$nextTick([callback]) 查看 vueJs 官网
用法:将回调延迟到下次 DOM 更新循环之后执行。在修改数据之后立即使用它,然后等待 DOM 更新。它跟全局方法 Vue.nextTick
一样,不同的是回调的 this
自动绑定到调用它的实例上。
更多推荐
所有评论(0)