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')
    },

参考:

https://blog.csdn.net/qq_27331631/article/details/104851801

https://blog.csdn.net/qq_27331631/article/details/107568589?utm_medium=distribute.pc_relevant.none-task-blog-baidulandingword-3&spm=1001.2101.3001.4242

Logo

前往低代码交流专区

更多推荐