el-tree设置节点默认选中并高亮效果

el-tree设置节点默认选中并高亮效果_第1张图片

 
      

  treeData: [],
      defaultProps: {
        children: "children",
        label: "columnName",
      },

      treeData: [],


    async getTree() {
      let obj = {};
      await columnList()
        .then((res) => {
          if (res.data && res.data.length > 0) {
            this.treeData = handleTree(res.data, "id");
            obj = this.treeData[0];
            this.$nextTick(() => {
              // todo 在这里设置
              this.$refs.tree.setCurrentKey(this.treeData[0].children[1].id)
            })
          } else {
            this.treeData = [];
            obj = {};
          }
          console.log("this.treeData", this.treeData)
        })
        .finally(() => {
          console.log(obj);
          this.nodeClick(obj);
        });
    },


  created() {
    this.getTree();
  },
  // 设置首行高亮效果
  this.$refs.tree.setCurrentKey(this.treeData[0].id)

你可能感兴趣的:(vue项目中常用操作,后台管理系统,vue.js,javascript,前端)