ant desgin vue 组件 <a-tree> 选中之后,再次点击不让其取消选中
问题描述:
在<a-tree>组件使用时,我们单选选中树结构得某一个节点,再次点击会取消选中,而在实际使用时,我们的需求是不让他取消选中,必须选中一个
如下图:
解决办法:
在树结构的选择事件,主动去设置选中的数据,让其触发选中事件
<a-tree
v-if="treeData.length > 0"
:tree-data="treeData"
show-icon
show-line
:default-expand-all="true"
:selectedKeys="selectedKeys" //最重要的是这个参数 为其设置选中的数据
@select="onSelect"
:replaceFields="replaceFields"
/>
//选中事件
onSelect(selectedKeys,e) {
this.selectedKeys = [e.node.dataRef.id] //直接赋值 参数selectKeys 如果再次点击 会变为空数组
if(e.selected){
this.$emit('onSelected', selectedKeys)
}
},

浙公网安备 33010602011771号