vue+Element-ui實現(xiàn)分頁效果

當我們向后臺請求大量數(shù)據(jù)的時候,并要在頁面展示出來,請求的數(shù)據(jù)可能上百條數(shù)據(jù)或者更多的時候,并不想在一個頁面展示,這就需要使用分頁功能來去完成了。

微信圖片_20190712171547.png

1.vue2.0+element-ui實現(xiàn)一個分頁功能,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="商品規(guī)格" 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]" //這是下拉框可以選擇的,每選擇一行,要展示多少內(nèi)容
                            :page-size="pagesize"         //顯示當前行的條數(shù)
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="tableData.length">    //這是顯示總共有多少數(shù)據(jù),
 </el-pagination>

需要data定義一些,tableData定義一個空數(shù)組,請求的數(shù)據(jù)都是存放這里面

data () {
      return {
                currentPage:1, //初始頁
                pagesize:10,    //    每頁的數(shù)據(jù)
                tableData: []
      }
  },
methods: {
        // 初始頁currentPage、初始每頁數(shù)據(jù)數(shù)pagesize和數(shù)據(jù)data
        handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每頁下拉顯示數(shù)據(jù)
        },
        handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //點擊第幾頁
        },
        handleUserList() {
            this.$http.get('http://localhost:3000/userList').then(res => {  //這是從本地請求的數(shù)據(jù)接口,
                this.tableData= res.body
            })
        }
    }

以上都是分頁所需的功能,也是自己在自己寫案例中所遇到的,并總結(jié)下方便查看嘿嘿

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 基于Vue的一些資料 內(nèi)容 UI組件 開發(fā)框架 實用庫 服務(wù)端 輔助工具 應(yīng)用實例 Demo示例 element★...
    嘗了又嘗閱讀 1,282評論 0 1
  • 前言 最近在做一個前后端分離的項目,前端使用 Vue+ Element UI,而后端則使用 Lumen 做接口開發(fā)...
    4Ark閱讀 1,223評論 0 2
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    柴東啊閱讀 15,960評論 2 140
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫 m...
    王喂馬_閱讀 6,585評論 1 77
  • 蒼穹之下,貧瘠的土地上,黃沙漫天,塵土飛揚。 來自遠方的考察者,遇到了衣衫襤褸的放羊娃。 考察者:“孩子,你在這兒...
    斯麥爾閱讀 729評論 0 5

友情鏈接更多精彩內(nèi)容