【效果】只有叶子节点可以被选中
【步骤】按步骤copy即可(vue2版本)
1、html中
<a-tree-select
v-model="ffid"
show-search
style="width: 100%"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请从标签树中选择"
allow-clear
multiple
:tree-default-expand-all="false"
:tree-data="treeData"
:replace-fields="{children:'children', key:'id', value: 'id', title: 'name'}"
>
</a-tree-select>
2、js中
2.1data中:
data () {
return {
ffid:''.
treeData: [{
name: 'parent 1',
id: 'parent 1',
children: [{
name: 'parent 1-0',
id: 'parent 1-0',
children: [{
name: 'my leaf',
id: 'leaf1'
}, {
name: 'your leaf',
id: 'leaf2'
}]
}, {
name: 'parent 1-1',
id: 'parent 1-1'
}]
}]
}
},
2.2mounted、method中:
mounted () {
this.treeData = this.dealData(this.treeData)
},
methods () {
dealData (param) {
return param.map(item => ({
...item,
disabled: !!item.children,
children: item.children ? this.dealData(item.children) : []
}))
},