vue pagination 前端单独分页处理
发布日期: 2020-08-18 00:00:00
点击次数: 817
点击次数: 817
大字
小字
<template>
<div class="g-index">
<el-table
:data="
tableData.slice((currentpage - 1) * pagesize, currentpage * pagesize)
"
style="width: 100%"
>
<el-table-column prop="date" label="日期" width="280"></el-table-column>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
</el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentpage"
:page-size="2"
layout="total, prev, pager, next"
:total="5"
>
</el-pagination>
</div>
</template>
<script>
import Vue from 'vue'
export default {
data() {
return {
tableData: [
{
date: '2020-05-02',
name: 'jack1',
address: '上海市浦东新区张杨路 1518 弄'
},
{
date: '2020-05-04',
name: 'jack2',
address: '上海市浦东新区张杨路 1517 弄'
},
{
date: '2020-05-01',
name: 'jack3',
address: '上海市浦东新区张杨路 1519 弄'
},
{
date: '2020-05-03',
name: 'jack4',
address: '上海市浦东新区张杨路 1516 弄'
},
{
date: '2020-05-04',
name: 'jack5',
address: '上海市浦东新区张杨路 1517 弄'
}
],
// 默认显示第一条
currentpage: 1,
pagesize: 2
}
},
methods: {
handleSizeChange(val) {},
handleCurrentChange(val) {
this.currentpage = val
}
}
}
</script>
<style lang="scss" scope="">
h1 {
color: #ccc;
width: 500px;
}
</style>
<div class="g-index">
<el-table
:data="
tableData.slice((currentpage - 1) * pagesize, currentpage * pagesize)
"
style="width: 100%"
>
<el-table-column prop="date" label="日期" width="280"></el-table-column>
<el-table-column prop="name" label="姓名" width="180"></el-table-column>
<el-table-column prop="address" label="地址"></el-table-column>
</el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentpage"
:page-size="2"
layout="total, prev, pager, next"
:total="5"
>
</el-pagination>
</div>
</template>
<script>
import Vue from 'vue'
export default {
data() {
return {
tableData: [
{
date: '2020-05-02',
name: 'jack1',
address: '上海市浦东新区张杨路 1518 弄'
},
{
date: '2020-05-04',
name: 'jack2',
address: '上海市浦东新区张杨路 1517 弄'
},
{
date: '2020-05-01',
name: 'jack3',
address: '上海市浦东新区张杨路 1519 弄'
},
{
date: '2020-05-03',
name: 'jack4',
address: '上海市浦东新区张杨路 1516 弄'
},
{
date: '2020-05-04',
name: 'jack5',
address: '上海市浦东新区张杨路 1517 弄'
}
],
// 默认显示第一条
currentpage: 1,
pagesize: 2
}
},
methods: {
handleSizeChange(val) {},
handleCurrentChange(val) {
this.currentpage = val
}
}
}
</script>
<style lang="scss" scope="">
h1 {
color: #ccc;
width: 500px;
}
</style>