vue el-tree 默认选中第一条

如果是多层级树,等树加载完成后执行以下语句:

         this.$nextTick(() => {
            document
              .querySelector('[role=group] .el-tree-node__children .el-tree-node__content')
              .click();
          });

如:

 activated () {
      this.$http({
          url: this.$http.adornUrl('/menuList'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.menuList = treeDataTranslate(data.menuList)
          } else {
            this.menuList = []
          }
        }).then(() => {
          this.$nextTick(() => {
            document
              .querySelector('[role=group] .el-tree-node__children .el-tree-node__content')
              .click();
          });
        })
    }

如果觉得树的选中颜色太浅,可以修改css:

你可能感兴趣的:(js,vue.js,javascript,前端)