//this.$refs.tree.getCheckedNodes() //树选中的值
//this.$refs.tree.getCheckedKeys() //树选中的id
//this.$refs.tree.setCurrentKey(id);//默认高亮
default-expand-all --默认展开全部
highlight-current --高亮
:filter-node-method="filterNode" --筛选input
:expand-on-click-node="false" --点击图标才展开
node-key="id" --getCheckedKeys必须绑定id
:props="{ -- 格式化可写在标签内
label: 'name',
value:'id',
}"
<div class="tree-box">
<span class="tree-title">标题</span>
<el-input
placeholder="请输入"
v-model="treeList.filterText"
suffix-search="el-icon-date">
</el-input>
<el-tree
class="filter-tree"
:data="treeList.treeData"
:props="treeList.treeProps"
default-expand-all
:expand-on-click-node="false"
highlight-current
:filter-node-method="filterNode"
ref="tree"
@node-click="treeClick">
</el-tree>
</div>
<script>
data() {
return {
treeList:{
filterText:"",
treeData:[],
treeProps: {
label: 'name',
value:'id',
}
},
}
}
treeClick(data){
console.log(data)
},
filterNode(value, data) {
if (!value) return true;
return data.name.indexOf(value) !== -1;
},
watch: {
'treeList.filterText'(val) {
this.$refs.tree.filter(val);
}
},
</script>
<style>
.tree-box{
width: 268px;
height: 310px;
border: solid 1px #e9e9e9;
border-radius: 4px;
margin-right: 20px;
float: left;
.tree-title{
display: block;
color: #666666;
font-size: 14px;
background-color: #f1f2f4;
border-radius: 4px 4px 0 0;
text-indent: 18px;
width: 100%;
height: 40px;
line-height: 40px;
}
.el-input{
display: inherit;
margin: 10px auto;
width: 90%;
}
.el-tree{
margin: 10px auto;
height: 200px;
width: 90%;
overflow: auto;
}
}
</style>