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)
	}
}

posted @ 2024-08-06 20:35  Felix_Openmind  阅读(68)  评论(0编辑  收藏  举报