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>

结果

相关推荐
未来之窗软件服务12 分钟前
自建开发工具IDE(二)文件托拽读取——东方仙盟炼气期
开发语言·前端·javascript·仙盟创梦ide·东方仙盟
GISer_Jing1 小时前
OpenCV头文件路径配置终极修复指南
javascript·opencv·webpack
s9123601012 小时前
【Rust】使用lldb 调试core dump
前端·javascript·rust
不是鱼2 小时前
Canvas学习笔记(一)
前端·javascript·canvas
我有一棵树2 小时前
React 中 useRef 和 useState 的使用场景区别
前端·javascript·react.js
想努力找到前端实习的呆呆鸟2 小时前
Uniapp如何下载图片到本地相册
前端·vue.js·微信小程序
fmk10233 小时前
Vue中的provide与inject
前端·javascript·vue.js
米兰小铁匠173 小时前
js深入之从原型到原型链
javascript·面试
Smile_Gently3 小时前
Vue 2 前端项目实现 在线IDE 功能
javascript
云枫晖4 小时前
Vue3 响应式原理:从零实现 Reactive
前端·vue.js