vue分页?

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>

结果

相关推荐
无责任此方_修行中1 小时前
每周见闻分享:杂谈AI取代程序员
javascript·资讯
dorabighead3 小时前
JavaScript 高级程序设计 读书笔记(第三章)
开发语言·javascript·ecmascript
林的快手4 小时前
CSS列表属性
前端·javascript·css·ajax·firefox·html5·safari
bug总结5 小时前
新学一个JavaScript 的 classList API
开发语言·javascript·ecmascript
网络安全-老纪5 小时前
网络安全-js安全知识点与XSS常用payloads
javascript·安全·web安全
yqcoder5 小时前
Express + MongoDB 实现在筛选时间段中用户名的模糊查询
java·前端·javascript
十八朵郁金香5 小时前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript
计算机-秋大田6 小时前
基于Spring Boot的兴顺物流管理系统设计与实现(LW+源码+讲解)
java·vue.js·spring boot·后端·spring·课程设计
GDAL6 小时前
HTML 中的 Canvas 样式设置全解
javascript
GDAL7 小时前
HTML Canvas clip 深入全面讲解
前端·javascript·canvas