<el-tree
ref="refTree"
:data="treeData"
show-checkbox
node-key="id"
highlight-current
:props="defaultProps"
default-expand-all
:expand-on-click-node="false"
:filter-node-method="filterTree"
@node-click="nodeClick"
>
</el-tree>
// 获取菜单树
getMenuTree() {
const params = {
name: '',
link_url: '',
parent_id: ''
}
this.spinShow = true
getMenuTree(params)
.then(res => {
this.spinShow = false
if (res.code == 200) {
this.treeData = res.data
this.treeIdRecursion(this.treeData)
}
})
.catch(err => {
this.spinShow = false
console.log(err)
})
},
// 递归判断是否含有已选中的id
treeIdRecursion(treeD) {
const treeIngIds = [29, 28]
const treeDataAllIds = []
for (let i = 0; i < treeD.length; i++) {
if (treeD[i].children && treeD[i].children.length > 0) {
this.treeIdRecursion(treeD[i].children)
} else {
treeDataAllIds.push(treeD[i].id)
for (let j = 0; j < treeIngIds.length; j++) {
if (treeDataAllIds.indexOf(treeIngIds[j]) > -1) {
// 设置默认样式选中
this.$nextTick(()=>{
this.$refs.refTree.setCurrentKey(treeIngIds[j]);
})
// 设置复选框默认选中---回显
this.$nextTick(() => {
this.$refs.refTree.setCheckedKeys(treeIngIds)
})
}
}
}
}
},
版权声明:本文为qq_41904178原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。