AntDesignVue的a-tree实现selectable和checkable同步
无论是点击勾选框还是点击树中的title名称 选中逻辑同步
<a-tree
checkable
selectable
v-model:tree-data="treeData"
v-model:selectedKeys="selectedKeys"
v-model:checkedKeys="checkedKeys"
@select="handleTreeSelect"
>
</a-tree>
const handleTreeSelect = (selectedKeys, e) => {
const {node: {dataRef: {key}}} = e
if(isEmpty(key)) return
if(e.selected) {
checkedKeys.value = [
...checkedKeys.value,
key
]
} else {
checkedKeys.value = checkedKeys.value.filter(checkKey => checkKey !== key)
}
}
学而不思则罔,思而不学则殆!