elementUI Tree 树形控件实现单选+获取树形控件单选框勾选内容

 

html部分

<el-tree
                    :data="data"
                    show-checkbox
                    node-key="id"
                    ref="tree"
                    check-strictly
                    highlight-current
                    @check-change="handleClick" 
                    :props="defaultProps"
                   
                   
  >

js部分

data:[{
          id: 0,
          label: '一级菜单',
          children: [
          {
            id: 1,
            label: '二级1-1',
          },
          
          ]
          }],
          defaultProps: {
            children: 'children',
            label: 'label'
          }

...

 
 handleClick(data,checked, node){
      if(checked){
        //关键
        this.$refs.tree.setCheckedNodes([data]);
      }
    },


....

获取勾选框的内容  Array[id]   

getCheckedKeys和getHalfCheckedKeys都是官方文档方法,组合起来 获取当前 树状插件  当前的勾选框checkout 内容 

 let resArr=this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys());
        

扩展参考(及其 屏蔽父级勾选框的方法)

https://blog.csdn.net/lianzhang861/article/details/91988151

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值