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

相关推荐
晚霞的不甘4 分钟前
Flutter for OpenHarmony:注入灵魂:购物车的数据驱动与状态管理实战
android·前端·javascript·flutter·前端框架
Marshmallowc18 分钟前
React useState 数据不同步?深度解析无限滚动中的“闭包陷阱”与异步更新丢失问题
前端·javascript·react.js·闭包·fiber架构
前端 贾公子20 分钟前
npm 发包配置双重身份验证
前端·javascript·微信小程序·小程序·github
zhengfei61126 分钟前
CVE-2025-55182 的 POC,可在 Next.js 16.0.6 上运行
开发语言·javascript·ecmascript
xkxnq30 分钟前
第四阶段:Vue 进阶与生态整合(第 48 天)(Vue 与 Axios 整合:实现 HTTP 请求的封装与拦截)
前端·vue.js·http
weixin_BYSJ198743 分钟前
django农作物批发交易系统--附源码24008
java·javascript·spring boot·python·django·flask·php
辰风沐阳1 小时前
ES6 新特性: 解构赋值
前端·javascript·es6
程序辅导开发1 小时前
django体育用品数据分析系统 毕业设计---附源码28946
数据库·vue.js·python·mysql·django·sqlite
工业互联网专业1 小时前
基于Django的智能水果销售系统设计
数据库·vue.js·django·毕业设计·源码·课程设计
猫头鹰源码(同名B站)1 小时前
基于django+vue的时尚穿搭社区(商城)(前后端分离)
前端·javascript·vue.js·后端·python·django