ant design vue中tree的使用

树的第一层展开需要加上 default-expand-all和v-if="props.treeData.length>0

<a-tree

    class="draggable-tree"

    :tree-data="props.treeData"

    :replaceFields="{ children: 'children', title: 'name', key: 'id' }" //设置children,key值的字段

    default-expand-all  //展开树

    @select="clickRow"

    v-model:selectedKeys="rowKeys"

    v-if="props.treeData.length>0"  //如果树不展开就加这个v-if

  />

监听treeData,默认点击树的第一层第一个children(比较笨的方法)

watch(

  () => props.treeData,

  (val) => {

    val.forEach(item=>{

//判断rowKey是否有值和treeData第一层数据是有children

      if(item.children.length && rowKeys.value.length==0){

        rowKeys.value= [val[0].children[0].id];

        emit('select', rowKeys.value);

      }

    })

  },

);

需要点击第一个层的按钮不响应:

const clickRow = (selectedKeys, e) => {

  const arr = [];

   // 循环判断第一层不做传值

  props.treeData.forEach((item) => {

    if (item.id == selectedKeys) {

      arr.push(item);

    }

  });

  if (selectedKeys.length&&arr.length == 0) { //如果满足条件就做传参

    emit('select', selectedKeys);

  }

};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值