ant design vue树选择

 <a-card title="">
            <a slot="extra" @click="handleReset">重置</a>
            <div style="width: 100%; height: 500px; overflow-y: scroll">
              <a-tree
                showIcon
                :key="treeKey"
                :tree-data="treeData"
                :load-data="onLoadData"
                @select="onSelect"
                :replace-fields="replaceFields"
              >
                <a-icon slot="folder" type="folder" />
              </a-tree>
            </div>
          </a-card>
data(){
return{
 treeKey: 0,
 treeData: [],
 pid:null,
 id:null,
 replaceFields: {
        title: 'name',
        key: 'id',
      },
}
},
methods:{
 //重置
    handleReset() {
      this.queryParam = {
        pid: 0,
      }
      //表格刷新
      this.$refs.table.refresh(true)
      this.handelTree()
    },
     onLoadData(treeNode) {
      return new Promise((resolve) => {
        userGroupListTree({ pid: treeNode.eventKey }).then((res) => {
          if (res.data != null && res.data.length > 0) {
            res.data.map((item) => {
              item.slots = { icon: 'folder' }
            })
            treeNode.dataRef.children = res.data
            this.treeData = [...this.treeData]
            resolve()
          } else {
            resolve()
          }
        })
      })
    },
    handelTree() {
    //获取数据接口
      userGroupListTree().then((res) => {
        this.$nextTick(() => {
          res.data.map((item) => {
            item.slots = { icon: 'folder' }
          })
          this.treeData = res.data
        })
      })
      this.treeKey++
    },
    //被选中
    onSelect(selectedKeys, info) {
      if (info.selected) {
        this.queryParam = {
          pid: selectedKeys[0],
        }
      }
      this.$refs.table.refresh(true)
      this.selectedKeys = selectedKeys[0]
      this.id = info.node.dataRef.id
    },
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jiojio冲冲冲

能帮助你是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值