功能介绍:不利于后端接口,前端如何实现分页,下面给大家简单介绍一下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工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

用ascii字符画图像
SVG路径动画效果
利用CSS3做一个星级评分样式
如何利用css3+js做一个下雨效果
做一个好玩的时钟翻牌效果
利用html5+css3实现滚雪球效果(附代码)
js导出excel插件(兼容mac电脑Numbers表格)











