vue+Element-ui实现分页效果

当我们向后台请求大量数据的时候,并要在页面展示出来,请求的数据可能上百条数据或者更多的时候,并不想在一个页面展示,这就需要使用分页功能来去完成了。

微信图片_20190712171547.png

1.vue2.0+element-ui实现一个分页功能,element-ui这个组件特别丰富,分页中给我提供了一个Pagination 分页,使用Pagination 快速完成分页功能

<el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column prop="id" label="编号" show-overflow-tooltip width="auto"></el-table-column>
                <el-table-column prop="goods_name" label="商品名称" show-overflow-tooltip width="auto"></el-table-column>
                <el-table-column prop="goods_spec" label="商品规格" width="auto"></el-table-column>
                <el-table-column prop="store_name" label="商家名称" width="auto"></el-table-column>
                <el-table-column prop="order_sn" label="订单编号" width="auto"></el-table-column>
                <el-table-column prop="stock" label="库存" width="auto">
                    <template slot-scope="scope">
                        <el-button type="text" size="mini" v-if="scope.row.stock>0">入库</el-button>
                        <el-button type="text" size="mini" style='color: #11b559;' v-if="scope.row.stock<0">出库</el-button>
                    </template>
                </el-table-column>
                
                <el-table-column prop="ctime" label="日志时间" width="auto"></el-table-column>

</el-table>

<el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="currentPage"
                            :page-sizes="[5, 10, 20, 40]" //这是下拉框可以选择的,每选择一行,要展示多少内容
                            :page-size="pagesize"         //显示当前行的条数
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="tableData.length">    //这是显示总共有多少数据,
 </el-pagination>

需要data定义一些,tableData定义一个空数组,请求的数据都是存放这里面

data () {
      return {
                currentPage:1, //初始页
                pagesize:10,    //    每页的数据
                tableData: []
      }
  },
methods: {
        // 初始页currentPage、初始每页数据数pagesize和数据data
        handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
        },
        handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
        },
        handleUserList() {
            this.$http.get('http://localhost:3000/userList').then(res => {  //这是从本地请求的数据接口,
                this.tableData= res.body
            })
        }
    }

以上都是分页所需的功能,也是自己在自己写案例中所遇到的,并总结下方便查看嘿嘿

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 基于Vue的一些资料 内容 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 element★...
    尝了又尝阅读 1,258评论 0 1
  • 前言 最近在做一个前后端分离的项目,前端使用 Vue+ Element UI,而后端则使用 Lumen 做接口开发...
    4Ark阅读 1,203评论 0 2
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    柴东啊阅读 15,943评论 2 140
  • UI组件 element- 饿了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的组件库 m...
    王喂马_阅读 6,561评论 1 77
  • 苍穹之下,贫瘠的土地上,黄沙漫天,尘土飞扬。 来自远方的考察者,遇到了衣衫褴褛的放羊娃。 考察者:“孩子,你在这儿...
    斯麦尔阅读 721评论 0 5

友情链接更多精彩内容