Vue3+antd实现分页功能

1.html中代码(在对应的地方添加)

 <a-pagination 
                    v-model:current="current" 
                    :total="total" 
                    v-model:page-size="pageSize"
                    :showSizeChanger="false"
                    :hideOnSinglePage="true"
                    style="margin-top: 20px;text-align: right;"
                    @change="checkTotal"/>

2.在script中定义参数

const current = ref(1);//默认展示第几页
const total = ref(0);//总的条数
const pageSize = ref(10);//默认一页展示的条数
const userList = ref([]);//数据得list

3.翻页的change事件

(getUserPageList是后端接口,具体传的参数根绝接口要求而定,翻页之后再给userList赋值即可)

const checkTotal = (page, pageSize) =>{getUserPageList({current:page,size:pageSize}).then((result)=>{
            userList.value = result.records
            total.value = result.total
        })
      }

希望对你们有帮助!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
首先,你需要在你的项目中安装Ant Design VueVue Router。然后,你可以创建一个收藏页面和一个收藏按钮组件。 在收藏按钮组件中,你需要添加一个点击事件来将当前页面添加到收藏夹中。你可以使用localStorage来存储收藏的页面。 在收藏页面中,你可以从localStorage中获取所有收藏的页面并将它们显示在页面上。你可以使用Ant Design Vue的Card组件来显示每个收藏的页面。 下面是一个简单的示例代码: 收藏按钮组件: ```html <template> <a-button type="primary" @click="addToFavorites">Add to favorites</a-button> </template> <script> export default { methods: { addToFavorites() { const currentUrl = window.location.href; let favorites = JSON.parse(localStorage.getItem('favorites')) || []; if (!favorites.includes(currentUrl)) { favorites.push(currentUrl); localStorage.setItem('favorites', JSON.stringify(favorites)); } } } }; </script> ``` 收藏页面: ```html <template> <div> <a-card v-for="(url, index) in favorites" :key="index"> <a href="url">{{ url }}</a> </a-card> </div> </template> <script> export default { data() { return { favorites: [] }; }, mounted() { const storedFavorites = localStorage.getItem('favorites'); if (storedFavorites) { this.favorites = JSON.parse(storedFavorites); } } }; </script> ``` 在你的路由器中,你需要创建一个指向收藏页面的路由: ```javascript import Favorites from './components/Favorites.vue'; const routes = [ { path: '/favorites', component: Favorites } ]; ``` 现在,你可以在你的应用程序中使用收藏按钮组件,并在收藏页面中查看和管理收藏的页面。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值