Vue Ant Design Vue table pagination - 表格分页

目录

效果

一、介绍

1、官方文档:Ant Design Vue — An enterprise-class UI components based on Ant Design and Vue.js

2、官方示例

二、准备工作

1、安装依赖包

2、示例版本

三、使用步骤

1、在main.ts引入

2、具体使用

四、完整示例

1、main.ts

2、example.vue


效果

一、介绍

1、官方文档:Ant Design Vue — An enterprise-class UI components based on Ant Design and Vue.js

Ant Design Vue — An enterprise-class UI components based on Ant Design and Vue.jsAn enterprise-class UI components based on Ant Design and Vueicon-default.png?t=N7T8https://3x.antdv.com/components/pagination-cn/

2、官方示例

二、准备工作

1、安装依赖包

# 选择一个你喜欢的包管理器

# NPM
$npm install ant-design-vue --save

#Yarn
$ yarn add ant-design-vue

注:也可以在浏览器中使用 script 和 link 标签直接引入文件,并使用全局变量 antd

Ant Design Vue — An enterprise-class UI components based on Ant Design and Vue.js

2、示例版本

"ant-design-vue": "^3.2.12",

三、使用步骤

1、在main.ts引入

import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'

app.use(Antd);

2、具体使用

  const page = ref(1);
  const pageSize = ref(2);
  const totals = ref(0);
  const paginationProp = ref({
    showSizeChanger: true, // 是否展示 pageSize 切换器,当 total 大于 50 时默认为 true
    showQuickJumper: true, // 是否可以快速跳转至某页
    pageSize, // 每页条数
    current: page, // 当前页数
    total: totals, // 数据总数
    showTotal: (totals) => `总 ${totals} 条数据`, // 用于显示数据总量和当前数据顺序
    onChange: pageChange, // 页码或 pageSize 改变的回调,参数是改变后的页码及每页条数
    onShowSizeChange: pageSizeChange, // pageSize 变化的回调
    pageSizeOptions: ['2', '3'], // 指定每页可以显示多少条
  });

四、完整示例

1、main.ts

import { createApp } from 'vue';
import App from './App.vue';
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'

const app = createApp(App);
app.use(Antd);
app.mount("#app");

2、example.vue

<template>
  <a-table
    :columns="columns"
    :data-source="tableData"
    bordered
    size="small"
    :pagination="paginationProp" />
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  const columns = [
    {
      title: '姓名',
      dataIndex: 'name',
      ellipsis: true,
    },
    {
      title: '身高',
      dataIndex: 'height', 
      ellipsis: true,
    },
    {
      title: '体重',
      dataIndex: 'weight',
      ellipsis: true,
    },
  ];
  const tableData = ref<any>([
    {
      key: '1',
      name: '张三',
      height: 180,
      weight: 165,
    },
    {
      key: '2',
      name: '李四',
      height: 178,
      weight: 146,
    },
    {
      key: '3',
      name: '王五',
      height: 182,
      weight: 168,
    },
    {
      key: '4',
      name: '赵六',
      height: 185,
      weight: 160,
    },
  ]);

  // 分页相关
  const page = ref(1);
  const pageSize = ref(2);
  const totals = ref(0);
  const paginationProp = ref({
    showSizeChanger: true, // 是否展示 pageSize 切换器,当 total 大于 50 时默认为 true
    showQuickJumper: true, // 是否可以快速跳转至某页
    pageSize, // 每页条数
    current: page, // 当前页数
    total: totals, // 数据总数
    showTotal: (totals) => `总 ${totals} 条数据`, // 用于显示数据总量和当前数据顺序
    onChange: pageChange, // 页码或 pageSize 改变的回调,参数是改变后的页码及每页条数
    onShowSizeChange: pageSizeChange, // pageSize 变化的回调
    pageSizeOptions: ['2', '3'], // 指定每页可以显示多少条
  });

  function pageChange(p, pz) {
    page.value = p;
    pageSize.value = pz;
    getDataList();
  }
  function pageSizeChange(current, size) {
    page.value = current;
    pageSize.value = size;
    getDataList();
  }

  function getDataList() {
    // 获取表格数据的接口地址({pageNo: page.value, pageSize: pageSize.value }).then((data) => {
    //   const { current, pages, size, total, records } = data
    //   if(current > pages) {
    //     page.value = pages;
    //     getDataList();
    //   } else {
    //     tableData.value = records;
    //     pageSize.value = size;
    //     totals.value = total;
    //   }      
    // })
  }

  // getDataList();

</script>

<style scoped>
  :deep() .ant-table-cell {
    text-align: center !important;
  }
  
  :deep() .ant-table-pagination.ant-pagination {
    margin: 10px 0 0 0 !important;
  }
</style>

Ant Design Vue — An enterprise-class UI components based on Ant Design and Vue.js

 欢迎扫码下方二维码关注VX公众号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用 Vue Ant Design 中的 TablePagination 组件时,可以通过以下步骤将它们组合在一起: 1. 在 Vue 组件中引入 TablePagination 组件: ``` <template> <div> <a-table :columns="columns" :data-source="dataSource"> <a-pagination :total="total" :current="current" :page-size="pageSize" @change="onChange" /> </a-table> </div> </template> <script> import { Table, Pagination } from 'ant-design-vue'; export default { components: { 'a-table': Table, 'a-pagination': Pagination, }, data() { return { columns: [...], // 表格列定义 dataSource: [...], // 表格数据 total: 100, // 数据总数 current: 1, // 当前页码 pageSize: 10, // 每页数据条数 }; }, methods: { onChange(page) { // 处理分页变化事件 }, }, }; </script> ``` 2. 在 Table 组件中添加 Pagination 组件,并传入相关属性和事件处理函数。 其中,Pagination 组件接收三个属性: - `total`:数据总数; - `current`:当前页码; - `pageSize`:每页数据条数。 Pagination 组件还有一个 `@change` 事件,当分页变化时会触发该事件,此时可以调用事件处理函数来处理分页逻辑。 3. 在 data 中定义 `total`、`current` 和 `pageSize` 变量,并在 `onChange` 方法中处理分页变化逻辑。 以上就是在 Vue Ant Design 中使用 TablePagination 组件的方法。需要注意的是,TablePagination 组件都需要在组件中引入,并分别注册为自定义组件,才能在模板中使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值