Vue組件庫ElementUI實現表格列表分頁效果

ElementUI實現表格列表分頁效果教程,供大傢參考,具體內容如下

Element UI 是一套采用 Vue 2.0 作為基礎框架實現的組件庫,一套為開發者、設計師和產品經理準備的基於 Vue 2.0 的組件庫,提供瞭配套設計資源,幫助網站快速成型

<el-pagination>加上@size-change=”handleSizeChange、@current-change=”handleCurrentChange”處理當前頁和當前頁數的改變事件

<!--表格-->
<div class="formTable" id="formTable">
<el-table
  ref="Table"
  :data="apprItemData"
  :header-cell-style="headClass"
         row-key="approveItem"
         :tree-props="{children: 'children'}"
         height="420"
  border>
 <el-table-column
   type="selection"
   width="55">
 </el-table-column>
 <el-table-column
   label="序號"
   width="60"
   align="center">
  <template slot-scope="scope">{{scope.$index+1}}</template>
 </el-table-column>
 <el-table-column
   prop="itemCode"
   label="編碼">
 </el-table-column>
 <el-table-column
   prop="approveName"
   label="事項名稱">
 </el-table-column>
</el-table>
</div>
<!--表格分頁-->
<div class="pagination">
 <el-pagination
   background
   @size-change="handleSizeChange"
   @current-change="handleCurrentChange"
   :page-sizes="[5,10, 15, 20, 25]"
   :page-size="pageSize"
   layout="total, sizes, prev, pager, next, jumper"
   :total="totalRow">
 </el-pagination>
</div>
<script type="text/babel">
 var vm = new Vue({
     el: '#app',
     data:{
         apprItemData : [],
         currentPage: 1,  //當前頁
         totalRow: 0, //總頁數
         pageSize: 10 //當前顯示條數
     },
     computed: {},
     watch: {},
     created() {},
     mounted() {
         this.loadItemData();
},
     methods: {
         // 加載信息
loadItemData () {
             var pageSize = this.pageSize;
             var currentPage = this.currentPage;
             console.log("pageSize:"+pageSize+",currentPage:"+currentPage);
 //debugger;
 var geturl = '${root}/config/loadItemData.do?rows='+pageSize + '&page=' + currentPage;
             $.ajax({
                 type: 'get',
                 url:geturl,
                 contentType: "application/json; charset=utf-8",
                 success: function(data) {
                     //debugger;
                     console.log("totalRow:"+data.total);
                     vm.apprItemData = data.rows;
                     vm.totalRow = Number(data.total);
                 },
                 error: function(e) {
                     console.log("加載數據出現錯誤:",e);
                 }
             })
         }
         // 表頭樣式設置
         headClass() {
             return 'text-align: center;background:#F7F7F7;color:#1C1C1D;'
         },
         //頁數變換
         handleSizeChange(val) {
             this.pageSize = val;
             this.loadItemData();
         },
         //當前頁變換
         handleCurrentChange(val) {
             this.currentPage = val;
             this.loadItemData();
         }
     }
 });
</script>

以上就是本文的全部內容,希望對大傢的學習有所幫助,也希望大傢多多支持WalkonNet。