ElementUI中el-tree获取每个节点点击的选中状态

有时候需要获取el-tree每个节点的点击状态,可以通过以下方式,其中isCheck类型为布尔值

          <el-tree
            :data="organizationData"
            :props="defaultProps"
            :check-strictly="isAssociate"
            node-key="organizationId"
            :expand-on-click-node="false"
            @check="getCurrentNode"
            ref="tree"
          >
          </el-tree>

1.绑定@check事件,我这里是getCurrentNode,函数名自己随便写
2.绑定ref

    getCurrentNode(nodeObj, nodeState) {
    
    
      //判断当前状态是选中还是取消选中
      const isCheck = this.$refs.tree.getCheckedNodes().indexOf(nodeObj) > -1
      console.log(isCheck)
   }

猜你喜欢

转载自blog.csdn.net/weixin_43811753/article/details/129503566
今日推荐