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>

结果

相关推荐
运维全栈笔记2 小时前
Vue + Spring Boot 前后端分离项目部署笔记(若依 RuoYi-Vue 3.9.2)
运维·服务器·vue.js·spring boot·笔记·开源·开源软件
冬夜戏雪11 小时前
agent的trace 和eval
开发语言·前端·javascript
感谢一路走过的人13 小时前
AGGrid刷新数据后执行筛选
javascript·ag-grid
水獭比特13 小时前
工具都批准了,为什么还不能执行?给 Agent 补上第二道校验
javascript·人工智能·node.js
Simon_He13 小时前
一个渲染内核,五个框架包:我的流式 Markdown 渲染库是怎么长成“全家桶”的
前端·vue.js·markdown
夏雪coding13 小时前
JeecgBoot 动态路由踩坑(Vue2):刷新白屏、permissionList[0] 报 undefined,以及我最后为什么全删了
javascript·vue.js
默_笙14 小时前
😋 我让爬虫终于看到了我的网站,后端同事说"这也行?"(上):SEO 与渲染模式
前端·javascript
前进的程序员14 小时前
Codex破局:前端组件秒级生成|提速React/Vue开发,可复用提示词+实战调试经验
前端·vue.js·react.js·codex
JunjunZ15 小时前
Vue 3 文件预览的通用设计与实现
前端·vue.js