Vue + element树形控件复选框单选 and 添加 “全部”按钮 全选

复选框单选
<el-tree check-strictly show-checkbox :data="trreData" @check="checkClick" :props="defaultProps" 
node-key="id"   current-node-key :accordion="true" ref="tree"  ></el-tree>
//需要 node-key="id"   ref="tree"  
  // 单选
    checkClick (data, checked) {
      // // 单选
      if (checked) {
        this.$refs.tree.setCheckedNodes([]);
        this.$refs.tree.setCheckedNodes([data]);
        //交叉点击节点
      } else {
        this.$refs.tree.setCheckedNodes([]);
        //点击已经选中的节点,置空
      }
    },

在这里插入图片描述 (https://img-blog.csdnimg.cn/20210629143657989.png)

添加“全部按钮” 全选
<div class="trreShow" >
   <el-checkbox v-model="checkAll" @change="checkAllChange" style="margin-left:10px">全选</el-checkbox>
   <el-tree class="filter-tree" :data="data" :filter-node-method="filterNode"  node-key="id" ref="data" show-checkbox :props="defaultProps" ></el-tree>  
   //需要 node-key="id"  //  ref="data"  
</div>
// 全选
    checkAllChange (val) {
      if (this.checkAll) {
        this.$refs.data.setCheckedNodes(this.data);
      } else {
        this.$refs.data.setCheckedKeys([]);
      }
    },

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值