ElementUi 的checkedbox 联动问题

422 阅读1分钟

1show-checkbox 显示复选框

2default-expand-all 默认展开子选项

3check-strictly 设置true,可以关闭父子关联 点父级用户删除按钮,不选中删除用户api

       <el-tree
        :data="data"
        :props="{ label: 'name' }"
        default-expand-all
        :show-checkbox="true"
        :check-strictly="true"
      />

image.png

4获取到了数据了,把它填充到el-tree中,让某些个复选框处于选中状态 需要 setCheckedKeys + node-key 配合使用

<el-tree
      ref="refTree"
      :data="data"
      :props="{ label: 'name' }"
      :default-expand-all="true"
      :show-checkbox="true"
      :check-strictly="true"
      node-key="id"
    />

5调用setCheckedKeys

async fn() {
      const res = await getList()
      // 回填
      this.$refs.refTree.setCheckedKeys(res.data.permIds)
    },