html代碼
因?yàn)槲覍懺趖emplate中,也就是新建了組建中,貼出代碼。
<el-pagination small layout="prev, pager, next" :total="total" @current-change="current_change"> </el-pagination>
代碼中,small代表是否使用小型分頁(yè)樣式
layout代表組件布局,子組件名用逗號(hào)分隔
屬性: total代表總條目數(shù)
事件: current-change用于監(jiān)聽頁(yè)數(shù)改變,而內(nèi)容也發(fā)生改變
其他屬性可參見element官方API
http://element.eleme.io/#/zh-CN/component/pagination
監(jiān)聽方法,寫在methods中
methods:{ created:function(){ //加載班級(jí)的數(shù)據(jù) var url ='http://127.0.0.1:3000/clazz/findAll'; //向后臺(tái)獲取數(shù)據(jù) var vm = this; $.getJSON(url,function(data){ vm.clazzInfo = data; vm.total = data.length;//設(shè)置數(shù)據(jù)總數(shù)目!!! }); }, current_change:function(currentPage){ this.currentPage = currentPage; } }
其中url是在后臺(tái)express搭建起來的腳手架所設(shè)置好的路由。
在data中注冊(cè)使用的數(shù)據(jù)
因?yàn)槲沂侨肿?cè),data是個(gè)返回對(duì)象的函數(shù)
data:function(){ return { total:0,//默認(rèn)數(shù)據(jù)總數(shù) pagesize:7,//每頁(yè)的數(shù)據(jù)條數(shù) currentPage:1,//默認(rèn)開始頁(yè)面 } }
將數(shù)據(jù)綁定到tbody上
<el-table :data="searchInfo.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%">
其中searchInfo是我獲取到后臺(tái)數(shù)據(jù)的數(shù)組。
以上這篇利用vue和element-ui設(shè)置表格內(nèi)容分頁(yè)的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com