问题描述:

当el-tree 需要从后台拿到数据动态展示出来时,会出现一个父节点下面的所有子节点全部被勾选了,如图:

解决方案:

  <el-tree
            ref="tree"
            :check-strictly="checkStrictly"
            :data="routesData"
            :props="defaultProps"
            show-checkbox
            node-key="path"
            class="permission-tree"
          />

1.设置check-strictly 是一个变量checkStrictly 默认值是false

2.拿到接口数据后:

     this.checkStrictly = true  //重点:给数节点赋值之前 先设置为true
      this.$nextTick(() => {
        const routes = this.generateRoutes(this.role.routes) //拿到接口数据
        this.$refs.tree.setCheckedNodes(routes) //给树节点赋值
        this.checkStrictly = false //重点: 赋值完成后 设置为false
      })

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐