<template>
  <div class="tzgl_wrap">
        <a-tree
          :tree-data="treeData"
          @select="treeSelect"
          default-expand-all
        >
          <template slot="title" slot-scope="{ title }">
            <span>{{ title }}</span>
          </template>
        </a-tree>
  </div>
</template>

<script>
import {
  MainPageTree
} from '@/api/dwActivityManage'
export default {
  components: {
    Book
  },
  data() {
    return {
      treeData: [],
      treeInfo: {},
    }
  },
  mounted() {
    this.getTreeData()
  },
  methods: {
    getTreeData() {
      MainPageTree().then(res => {
        if (res.code == 200) {
          this.treeData = res.data
          // this.generateList(res.data)
        }
      })
    },
    treeSelect(e) {
    this.recursiveFilter(this.treeData, e[0])
    console.log(this.treeInfo,'======treeInfo')

    },
   // 通过key 获取树节点信息
    recursiveFilter(tree, keys) {
      let data = tree.filter(item => item.key == keys)
      if (data.length != 0) {
        this.treeInfo = data[0]
      } else {
        tree.map(item => {
          if (item.children) {
            //递归循环
            this.recursiveFilter(item.children, keys)
          }
        })
      }
      return data
    },
  }
}
</script>

打印结果:

在这里插入图片描述

Logo

前往低代码交流专区

更多推荐