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

相关推荐
学习笔记1012 小时前
第十五章认识Ajax(六)
前端·javascript·ajax
程序员杨工3 小时前
【原创】SpringBoot3+Vue3客户管理系统
vue.js·springboot
theOtherSky5 小时前
element+vue3 table上下左右键切换input和select
javascript·vue.js·elementui·1024程序员节
会联营的陆逊5 小时前
JavaScript 如何优雅的实现一个时间处理插件
javascript
over6975 小时前
浏览器里的AI魔法:用JavaScript玩转自然语言处理
前端·javascript
Amy_cx5 小时前
搭建React Native开发环境
javascript·react native·react.js
代码AI弗森5 小时前
Python × NumPy」 vs 「JavaScript × TensorFlow.js」生态全景图
javascript·python·numpy
疏狂难除6 小时前
关于spiderdemo第二题的奇思妙想
javascript·爬虫
渣渣盟6 小时前
探索Word2Vec:从文本向量化到中文语料处理
前端·javascript·python·文本向量化