数据分页显示

 前端页面分页



<body>
    <div id="app">
        <!-- tableData.slice((当前页数 - 1) * 每页条数, 当前页数*当前条数) -->
        <!-- tableData.slice((page -1) * limit , limit * page) -->
        <el-table :data="tableData.slice((page -1) * limit , limit * page)" border style="width: 100%">
            <el-table-column prop="id" label="ID" width="80"></el-table-column>
            <el-table-column prop="title" label="标题" width="180"></el-table-column>
            <el-table-column prop="body" label="内容"></el-table-column>
        </el-table>
        <el-pagination
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            :page-size="limit"
            :current-page="page"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange">
        </el-pagination>
    </div>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                tableData: [],
                total: 10,
                limit: 10,
                page: 1
            },
            created() {
                axios.get('http://jsonplaceholder.typicode.com/posts')
                .then(res => {
                    console.log(res)
                    this.tableData = [...res.data]
                    this.total = res.data.length
                })
            },
            methods: {
                handleSizeChange(val) {
                    // console.log(val)
                    this.limit = val
                    this.page = 1
                },
                handleCurrentChange(val) {
                    // console.log(val)
                    this.page = val
                }
            }
        })
    </script>
</body>

后端分页显示

<body>
    <div id="app">
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column prop="id" label="ID" width="80"></el-table-column>
            <el-table-column prop="title" label="标题" width="180"></el-table-column>
            <el-table-column prop="body" label="内容"></el-table-column>
        </el-table>
        <el-pagination
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            :page-size="limit"
            :current-page="page"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange">
        </el-pagination>
    </div>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                tableData: [],
                total: 10,
                limit: 10,
                page: 1
            },
            created() {
                axios.get('http://jsonplaceholder.typicode.com/posts')
                .then(res => {
                    console.log(res)
                    this.tableData = [...res.data]
                    this.total = res.data.length
                })
            },
            methods: {
                getData(obj) {
                    axios.get('http://jsonplaceholder.typicode.com/posts', {params: obj})
                    .then(res => {
                        this.tableData = [...res.data]
                    })
                },  
                handleSizeChange(val) {
                    this.limit = val
                    this.page = 1
                    this.getData({_page: this.page, _limit: val})
                },
                handleCurrentChange(val) {
                    this.page = val
                    this.getData({_page: val, _limit: this.limit})
                }
            }
        })
    </script>
</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值