el-tree in ElementUI gets the selected state of each node click

Sometimes it is necessary to obtain the click status of each node of the el-tree, which can be done in the following way, where the type of isCheck is a boolean value

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

1. Bind @check event, here is getCurrentNode, the function name can be written by yourself
2. Bind ref

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

Guess you like

Origin blog.csdn.net/weixin_43811753/article/details/129503566