功能介绍:不利于后端接口,前端如何实现分页,下面给大家简单介绍一下js代码,html语法自己理解一下!
具体实现代码如下:
export default {
data() {
return {
productList: [], //所有数据
totalPage: 1, // 统共页数,默认为1
currentPage: 1, //当前页
pageSize: 10, // 每页显示条数
currentPageData: [] //当前页显示内容
};
},
mounted() {
this.totalPage = Math.ceil(this.productList.length / this.pageSize);// 计算一共有几页
this.totalPage = this.totalPage == 0 ? 1 : this.totalPage;
this.setCurrentPageData();
},
methods: {
setCurrentPageData() {
let begin = (this.currentPage - 1) * this.pageSize;
let end = this.currentPage * this.pageSize;
this.currentPageData = this.productList.slice(
begin,
end
);
},
// 获取上一页
prevPage() {
console.log(this.currentPage);
if (this.currentPage == 1) return;
this.currentPage--;
this.setCurrentPageData();
},
// 获取下一页
nextPage() {
if (this.currentPage == this.totalPage)return ;
this.currentPage++;
this.setCurrentPageData();
}
}
}
vue项目动态设置background背景色,解决颜色被替换问题
wordpress文章nextpage分页最后添加“下一页”按钮
上面是“vue前端分页功能实现代码(附js代码)”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_16325.html
workflows工作流
一只可爱的毛茸茸的猫ComfyUI工作流
森林里一只邪恶的树妖ComfyUI工作流
星空星域星球comfyui工作流
蘑菇屋,梦幻家园comfyui工作流
一个男人正走进科幻的大门ComfyUI工作流
一头巨大的古代大象背后建着一座城市
沙漠里美丽的图阿雷格女孩ComfyUI工作流
一个可爱的口袋妖怪ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3动画loading效果
一个包含老黄历、佛历、道历、星宿等数据的日历网站
css3卡片动态滑动效果
纯css翻书效果
如何利用css3+js做一个下雨效果
纯css制作卡通头像(随鼠标转头)
利用css绘画棋盘布局(象棋)
利用css3做一个动态loading效果










