vue树结构el-tree重新加载后默认触发上次节点点击事件
template<el-tree :data="treeData" node-key="id" default-expand-all :expand-on-click-node="false" highlight-current :props="defaultProps" @node-click="handleNodeClick" v-loading="treeLoading" style=
·
template
<el-tree :data="treeData" node-key="id" default-expand-all :expand-on-click-node="false" highlight-current :props="defaultProps" @node-click="handleNodeClick" v-loading="treeLoading" style="min-width: 300px;"
ref="tree">
</el-tree>
data
currentTreeNode: '' // 初始化第一个点击节点为父节点
methods
// 组织机构树 部门树
getTreeData() {
this.treeLoading = true
this.treeData = []
this.$post(this.$apis.getAllOrgTreeNodes, {
token: this.$store.state.userInfo.token
}).then(res => {
if (res.data && res.data.length !== 0) {
this.treeData.push(res.data)
}
//'nextTick()' 在下次 DOM 更新循环结束之后执行延迟回调
// 默认点击
// this.$nextTick().then(() => {
// // 点击第一个节点
// // const firstNode = document.querySelector('.el-tree-node')
// // firstNode.click()
// })
this.$nextTick(() => {
this.$refs.tree.setCurrentKey(this.currentTreeNode !== '' ? this.currentTreeNode : this.treeData[0].id)
this.$nextTick(() => {
document.querySelector(".is-current").firstChild.click()
})
})
this.treeLoading = false
console.log(this.currentTreeNode, 'qq')
}).catch(err => {
this.treeLoading = false
})
},
// 区域树节点点击
handleNodeClick(data) {
console.log(data, '当前点击的树节点')
this.queryParams.organizationParentId = data.id
this.queryParams.organizationName = '' // 清空查询条件 部门名称
this.parentOrganiName = data.text // 上级区域
this.currentTreeNode = data.id // 保存当前点击的树节点的id
this.handleSearch('btn')
},
参考:
更多推荐
已为社区贡献17条内容
所有评论(0)