首先给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