v-clickoutside参考我其他有一篇博客写到了,点击除本身外的自定义事件
<el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" v-clickoutside="clickoutside"></el-tree>
数据
data: [{
label: '黎明社区作战单元',
children: [{
label: '一区',
children: [{
label: '一区一组',
},{
label: '一区二组'
}]
},{
label: '二区',
children: [{
label: '二区一组'
},{
label: '二区二组'
}]
},{
label: '三区',
children: [{
label: '三区一组'
},{
label: '三区二组'
}]
},{
label: '四区',
children: [{
label: '四区一组',
}]
},{
label: '五区',
children: [{
label: '五区一组'
}]
},{
label: '六区',
children: [{
label: '六区一组'
}]
}],
}],
js部分
handleNodeClick(data){
this.zhezhao=true; //这个是点击tree给了他一个全屏的遮罩
console.log(data,55555555555);
},
clickoutside(){
document.getElementsByClassName('el-tree-node__children')[0].style.display='none'
document.getElementsByClassName('el-tree-node__content')[0].click()
}