elementui 中el-table使用多选框时,select 与selection-change方法如下

我们先看下官网的介绍:
在这里插入图片描述
官网并没有描述两者的区别,那我们用代码试验一下:

1.select 方法

代码如下:

 <el-table v-loading="loading" :data="userList" @select="handleSelectionChange">
 </el-table>
handleSelectionChange(selection) {
    
    
      console.log(“调用了!”);
    },

当选中全部的时候不触发,选择单个触发
在这里插入图片描述
1.select 方法
代码如下:

 <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
 </el-table>
    handleSelectionChange(selection) {
    
    
      console.log('调用了');
      this.ids = selection.map((item) => item.field1);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

选择全部和单个均可以触发方法

两个方法传递的selection参数就是:渲染该行的对象数据

最终区别: election-change可以触发全选,而select 不可以

猜你喜欢

转载自blog.csdn.net/fd2025/article/details/124713119