<template>
<div>
<table class="table table-hover">
<tbody>
<tr v-for="(item,index) in page_arrs" :key="index">
<td>{{item.name}}</td>
</tr>
</tbody>
</table>
<div class="page">
<button class="btn btn-default" type="submit" @click="primaryPage">首页</button>
<button class="btn btn-default" type="submit" @click="prePage">上页</button>
<button
class="btn btn-default"
type="submit"
>{{current_page}}/{{Math.ceil(arrs.length/pagesize)}}</button>
<button class="btn btn-default" type="submit" @click="nextPage">下页</button>
<button class="btn btn-default" type="submit" @click="lastPage">尾页</button>
</div>
</div>
</template>
<script>
export default {
name: "abouttwo",
data() {
return {
arrs: [
{
name:
"您清楚了吗?(需客户确认)",
id: 1
},
{
name:
"您清楚了吗?(需客户确认)",
id: 2
},
{ name: "Larry", id: 3 },
{ name: "Tim", id: 4 },
{ name: "Tom", id: 5 },
{ name: "Jack", id: 6 },
{ name: "Otto", id: 1 },
{ name: "Jacob", id: 2 },
{ name: "Larry", id: 3 },
{ name: "Tim", id: 4 },
{ name: "Tom", id: 5 },
{ name: "Jack", id: 6 },
{ name: "Otto", id: 1 },
{ name: "Jacob", id: 2 },
{ name: "Larry", id: 3 },
{ name: "Tim", id: 4 },
{ name: "Tom", id: 5 },
{ name: "Jack", id: 6 }
],
currentPage: 1, //当前页号
pagesize: 1 //每页大小
};
},
computed: {
page_arrs() {
let { currentPage, pagesize } = this;
return this.arrs.slice(
(currentPage - 1) * pagesize,
currentPage * pagesize
);
},
current_page() {
return this.currentPage;
}
},
methods: {
primaryPage() {
this.currentPage = 1;
},
prePage() {
if (this.currentPage == 1) {
return;
}
this.currentPage = this.currentPage - 1;
},
nextPage() {
if (this.currentPage == Math.ceil(this.arrs.length / this.pagesize)) {
return;
}
this.currentPage = this.currentPage + 1;
},
lastPage() {
this.currentPage = Math.ceil(this.arrs.length / this.pagesize);
}
}
};
</script>
<style lang="less">
</style>
vue 实现简单分页功能
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 后端一次获取数据前端分页 bug:vue和element实现的后台分页,当前是第二页,点击搜索,强制设置curre...