html
html
<template>
<div style="width: 100%; display: flex; justify-content: center">
<div class="table_inner">
<!-- 列表 -->
<el-table
:data="tableData.slice((page - 1) * limit, page * limit)"
height="500"
style="width: 98%; user-select: none"
>
<el-table-column prop="id" label="id" />
<el-table-column prop="name" label="角色名称" />
<el-table-column prop="account" label="账户" />
<el-table-column prop="pass" label="密码" />
<el-table-column prop="" label="操作"
><template #default="scope">
<span
style="color: #53ac6f"
@click="bian(scope.row, scope.row.imgs)"
>编辑</span
>
<span style="color: red; margin-left: 10%" @click="dele(scope.row)"
>删除</span
>
</template>
</el-table-column>
</el-table>
</div>
</div>
<!-- 页数 -->
<div class="paging" style="margin-left: 2%">
<el-pagination
:current-page="page"
background
layout="total, sizes, prev, pager, next, jumper"
:total="total"
class="mt-4"
v-model:page-size="limit"
:page-sizes="[5, 10, 15, 20]"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</template>
script
javascript
<script setup lang="ts">
import axios from "axios";
import { ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
const tableData = ref([]);
const gid_data = ref([]);
function fun() {
axios({
url: "https://c2c.kuxia.top/pcapi/power/account_list", // url
params: {},
})
.then(function (res) {
console.log(res.data); // 成功回调
for (let i = 0; i < res.data.data.length; i++) {
gid_data.value.push(res.data.data[i]);
}
tableData.value = res.data.data;
tableData.value.sort(function (a, b) {
return a.id - b.id;
});
// 分页
tableData.value = [...res.data.data];
total.value = res.data.data.length;
})
.catch(function (err) {
console.log(err); // 失败回调
});
}
fun();
const limit = ref(5); // 每页数据
const page = ref(1); // 默认页数
const total = ref(0); // 总的数据
const handleSizeChange = (val) => {
limit.value = val;
};
const handleCurrentChange = (val) => {
page.value = val;
};
</script>
结果