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

相关推荐
老毛肚15 小时前
jeecg-boot-base-core 02 day
javascript·python
岁月宁静16 小时前
RAG 文档摄入全链路,从原理到生产落地
vue.js·人工智能·python
#麻辣小龙虾#19 小时前
基于vue3.0开发一款【固废与废气运维管理系统】(支持源码)
前端·vue.js·vue3
一 乐20 小时前
家政服务管理系统|基于springboot + vue家政服务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·家政服务管理系统
烬羽20 小时前
后端返回的 JSON 字符串,浏览器怎么"看懂"的?——Ajax 全链路拆解
javascript
半个落月21 小时前
一个新手用 Bun + Axios 调通 DeepSeek API 的实践记录
javascript
不好听61321 小时前
深入理解链表:线性数据结构的另一面
javascript·数据结构
林希_Rachel_傻希希21 小时前
学React治好了我的焦虑症,1小时速通React 前20分钟。
前端·javascript·面试
小林ixn21 小时前
从 Ajax 到异步编程:JSON 序列化、Event Loop 与 XHR 请求完全解析
javascript
丷丩1 天前
MapLibre GL JS第47课:添加动画图标
javascript·gis·动画·mapbox·maplibre