Element-ui官網給的方法
getCheckedKeys() { console.log(this.$refs.tree.getCheckedKeys()); },
這種只有在所有子級都被選中的情況下才能獲得父級的id,如果不選中所有的子級那么獲取得到的id就只有子級的。但是一般提交數據時后台都需要父級id的。
1.找到node_modules/element-ui/lib/element-ui.common.js文件
2.按Ctrl+F搜索TreeStore.prototype.getCheckedKeys這個方法
3.把if(node.checked)改為if (node.checked||node.indeterminate) 如下圖:
4.保存重啟項目console.log(this.$refs.tree.getCheckedKeys());這樣就可以看到父級和子級的id了
原文地址:https://www.cnblogs.com/qing619/p/8144584.html