element-ui 报错Cannot read property 'setCheckedKeys' of undefined"

Transfer: https://blog.csdn.net/qq_36437172/article/details/86137825

[Vue warn]: Error in event handler for "click": "TypeError: Cannot read property 'setCheckedKeys' of undefined"

This error is because your dom element has not finished loading, you want to use setCheckedKeys set the node currently checked. That is, you write this $ refs.tree.setCheckedKeys (list);. This tree has not been loaded inside out.

solution:

this.$nextTick(() => {
    this.$refs.tree.setCheckedKeys(list)
});

(1) Vue.nextTick ([callback, context]) View vueJs official website

Usage: execution delayed callback after the next update cycle DOM. Using this method immediately after modifying the data, get the DOM updated.

(2) vm. $ NextTick ([callback]) View vueJs official website

After the callback execution delayed until the next update cycle DOM: usage. Use it immediately after modifying the data, and then wait for DOM updates. It is now a global method Vue.nextTick the same, except that this automatic callback instance bound to call it.

Guess you like

Origin blog.csdn.net/Dongguabai/article/details/90310845