element plus table组件多选获取数据id

首先给table加上 @selection-change="handleSelectionChange"事件

示例

html 复制代码
<el-table @selection-change="handleSelectionChange" stripe
        :data="data?.slice((currentPage3 - 1) * pageSize3, currentPage3 * pageSize3)" style="width: 100%">
        <!-- 复选框 -->
        <el-table-column fixed type="selection" width="40" align="center" />
        <el-table-column prop="id" label="序号" width="60" align="center" />
        <el-table-column prop="name" label="店铺名称" align="center" />
        <el-table-column prop="storetypename" width="110" label="店铺分类" align="center" />
        <el-table-column prop="img" label="店铺图片" align="center">
          <template #default="scope">
            <el-image preview-teleported="true" style="width: 40px; height: 40px;" :src="url + scope.row.img"
              :zoom-rate="1.2" :max-scale="7" :min-scale="0.2" :preview-src-list="[url + scope.row.img]"
              fit="cover" /></template>
        </el-table-column>
        <el-table-column label="认证" align="center">
          <template #default="scope">
            <el-button size="small" v-if="scope.row.type == 3 ? true : false" type="success" plain>通过</el-button>
            <el-button size="small" v-if="scope.row.type == 2 ? true : false" type="danger" plain>驳回</el-button>
            <el-button size="small" v-if="scope.row.type == 1 ? true : false" type="danger" plain>待认证</el-button>
          </template>
        </el-table-column>
        <el-table-column label="服务类型" show-overflow-tooltip align="center">
          <template #default="scope">
            <el-button size="small" type="primary" plain>{{ scope.row.busin }}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="上下架" align="center">
          <template #default="scope">
            <el-switch @click="upelseload(scope.row)" :model-value="scope.row.status" :active-value="2"
              :inactive-value="1" />
          </template>
        </el-table-column>

        <el-table-column prop="name" label="操作" width="200" align="center">
          <template #default="scope">
            <el-button @click="sounnc(scope.row)" size="small" type="warning" plain>审核</el-button>
            <el-button @click="serve(scope.row)" size="small" type="primary" plain>服务</el-button>
            <el-button @click="open(scope.row)" size="small" type="danger" plain>删除</el-button>
          </template>
        </el-table-column>

      </el-table>

然后写上

javascript 复制代码
// 多选
const data_id = ref([]);
const multipleSelection = ref([]);
//复选框事件
const handleSelectionChange = val => {
  multipleSelection.value = val;
  // 重置
  data_id.value = [];
  multipleSelection.value.filter(item => {
    data_id.value.push(item.id);
  });
  console.log(data_id.value);
};

这个打印的console.log(data_id.value);就是我们要的列表id

相关推荐
qq_406176141 天前
深入浅出 Pinia:Vue3 时代的状态管理新选择
javascript·vue.js·ecmascript
德育处主任Pro1 天前
前端元素转图片,dom-to-image-more入门教程
前端·javascript·vue.js
叫我一声阿雷吧1 天前
JS 入门通关手册(23):JS 异步编程:回调函数与异步本质
javascript·es6·前端面试·回调函数·回调地狱·js异步编程·异步本质
zayzy1 天前
前端八股总结
开发语言·前端·javascript
今天减肥吗1 天前
前端面试题
开发语言·前端·javascript
小J听不清1 天前
CSS 外边距(margin)全解析:取值规则 + 实战用法
前端·javascript·css·html·css3
前端小超超1 天前
Vue计算属性computed:可写与只读的区别
前端·javascript·vue.js
爱学习的程序媛1 天前
【Web前端】Pinia状态管理详解
前端·vue.js·typescript
java1234_小锋1 天前
分享一套优质的SpringBoot+Vue咖啡商城系统
vue.js·spring boot·咖啡商城
小J听不清1 天前
CSS 边框(border)全解析:样式 / 宽度 / 颜色 / 方向取值
前端·javascript·css·html·css3