久久精品精选,精品九九视频,www久久只有这里有精品,亚洲熟女乱色综合一区
    分享

    vue分頁(yè)組件table

     163九九 2019-03-12

    這篇文章主要為大家詳細(xì)介紹了vue分頁(yè)組件table-pagebar使用入門實(shí)例,具有一定的參考價(jià)值,可以用來(lái)參考一下。

    感興趣的小伙伴,下面一起跟隨512筆記的小編兩巴掌來(lái)看看吧!

    之前一直接觸都是原始的前端模型,jquery+bootstrap,冗雜的dom操作,繁瑣的更新綁定。接觸vue后,對(duì)前端MVVM框架有了全新的認(rèn)識(shí)。本文是基于webpack+vue構(gòu)建,由于之前的工作主要是基于java的服務(wù)端開發(fā)工作,對(duì)前端框架和組件的理解,不夠深入,借此來(lái)記錄在前端框架使用和構(gòu)建中的點(diǎn)點(diǎn)滴滴。

    此分頁(yè)組件參照于bootstrap-datatable底部分頁(yè)開發(fā)完成,相關(guān)參數(shù)增加自定義功能。

    底部分頁(yè)組件主要由左側(cè)當(dāng)前數(shù)據(jù)項(xiàng)數(shù)量顯示和右側(cè)分頁(yè)頁(yè)碼兩部分組成。組件代碼如下: 

    代碼如下:

    <template xmlns:v-on="http://www./1999/xhtml"
     xmlns:v-bind="http://www./1999/xhtml">
     <div class="page-bar">
     <div class="page-size">
     <div>
     <select v-on:change="menuChange()" v-model="limit">
     <option v-for="item in menu" v-bind:value="item">{{item}}</option>
     </select>
     記錄/頁(yè),顯示第 {{start}} 至 {{end}} 項(xiàng)記錄,共 {{totalSize}} 項(xiàng)
     </div>
     </div>
     <div class="page-con">
     <ul>
     <li><a v-on:click="firstClick()" v-bind:class="{ 'disabled': cur == 1}">首頁(yè)</a></li>
     <li><a v-on:click="preClick()" v-bind:class="{ 'disabled': cur == 1}">上一頁(yè)</a></li>
     <li v-for="per in pages" v-bind:class="{ 'active': cur == per}">
     <a v-on:click="pageClick(per)">{{ per }}</a>
     </li>
     <li><a v-on:click="nextClick()" v-bind:class="{ 'disabled': cur == totalPage}">下一頁(yè)</a></li>
     <li><a v-on:click="lastClick()" v-bind:class="{ 'disabled': cur == totalPage}">尾頁(yè)</a></li>
     <li><a>共<i>{{totalPage}}</i>頁(yè)</a></li>
     </ul>
     </div>
     <div class="clear-both"></div>
     </div>
    </template>
    
    <script>
     import Ajax from '../ajax'
    
     export default{
     props: ['page-model'],
     data () {
     return {
     // 初始頁(yè)
     cur: 1,
     // 請(qǐng)求地址
     url: this.pageModel.url ? this.pageModel.url : "",
     // 請(qǐng)求參數(shù)
     param: this.pageModel.param ? this.pageModel.param : {},
     // 請(qǐng)求方法 默認(rèn)為GET請(qǐng)求
     method: this.pageModel.method ? this.pageModel.method : 'GET',
     // 每頁(yè)顯示數(shù)量 默認(rèn)每頁(yè)顯示10條
     limit: this.pageModel.menu ? this.pageModel.menu[0] : 10,
     // 底部分頁(yè)基數(shù) 默認(rèn)5
     perSize: this.pageModel.perSize ? this.pageModel.perSize : 5,
     // 每頁(yè)顯示數(shù)量 下拉選項(xiàng)
     menu: this.pageModel.menu ? this.pageModel.menu : [5, 10, 50],
     // 分頁(yè)參數(shù) 自定義名稱
     pageParamName: this.pageModel.pageParamName ? this.pageModel.pageParamName : ['page', 'limit'],
     // 當(dāng)前列表顯示記錄起始數(shù)
     start: 0,
     // 當(dāng)前列表顯示記錄結(jié)束數(shù)
     end: 0,
     // 總頁(yè)數(shù)
     totalPage: 0,
     // 記錄總數(shù)
     totalSize: 0,
     // 分頁(yè)請(qǐng)求返回?cái)?shù)據(jù)
     dataList: []
     }
     },
     ready () {
     this.getData();
     },
     methods: {
     // 首頁(yè)
     firstClick: function () {
     if (this.cur > 1) {
     this.cur = 1;
     this.getData();
     }
     },
     // 尾頁(yè)
     lastClick: function () {
     if (this.cur < this.totalPage) {
     this.cur = this.totalPage;
     this.getData();
     }
     },
     // 上一頁(yè)
     preClick: function () {
     if (this.cur > 1) {
     this.cur--;
     this.getData();
     }
     },
     // 下一頁(yè)
     nextClick: function () {
     if (this.cur < this.totalPage) {
     this.cur++;
     this.getData();
     }
     },
     // 頁(yè)碼
     pageClick: function (data) {
     if (data != this.cur) {
     this.cur = data;
     this.getData();
    
     }
     },
     // 刷新顯示記錄數(shù)
     refreshPageCon: function () {
     this.start = (this.cur - 1) * this.limit + 1;
     if (this.totalSize >= this.limit * this.cur) {
     this.end = this.limit * this.cur;
     } else {
     this.end = this.totalSize;
     }
     },
     // 分頁(yè)請(qǐng)求
     getData: function () {
     let _this = this;
     this.param[this.pageParamName[0]] = this.cur;
     this.param[this.pageParamName[1]] = this.limit;
     Ajax({
     url: _this.url,
     method: _this.method,
     data: _this.param,
     callback: function (res) {
     // 返回結(jié)果數(shù)據(jù)集
     this.dataList = res.data;
     // 返回總記錄數(shù)
     _this.totalSize = 25;
    
     _this.totalPage = Math.ceil(_this.totalSize / _this.limit);
     _this.refreshPageCon();
     _this.$dispatch('refresh', this.dataList);
     }
     });
     },
     // 每頁(yè)顯示記錄數(shù) 下拉
     menuChange: function () {
     this.getData();
     },
     getPage: function (curPage, totalPage, pageNum) {
     var leftPage, rightPage;
     curPage = curPage > 1 ? curPage : 1;
     curPage = curPage > totalPage ? totalPage : curPage;
     totalPage = curPage > totalPage ? curPage : totalPage;
     // 左側(cè)頁(yè)數(shù)
     leftPage = curPage - Math.floor(pageNum / 2);
     leftPage = leftPage > 1 ? leftPage : 1;
    
     // 右側(cè)頁(yè)數(shù)
     rightPage = curPage + Math.floor(pageNum / 2);
     rightPage = rightPage > totalPage ? totalPage : rightPage;
    
     var curPageNum = rightPage - leftPage + 1;
     // 左側(cè)調(diào)整
     if (curPageNum < pageNum && leftPage > 1) {
     leftPage = leftPage - (pageNum - curPageNum);
     leftPage = leftPage > 1 ? leftPage : 1;
     curPageNum = rightPage - leftPage + 1;
     }
    
     // 右側(cè)調(diào)整
     if (curPageNum < pageNum && rightPage < totalPage) {
     rightPage = rightPage + (pageNum - curPageNum);
     rightPage = rightPage > totalPage ? totalPage : rightPage;
     }
    
     var arr = [];
     for (var i = leftPage; i <= rightPage; i++) {
     arr.push(i);
     }
     return arr;
     }
     },
     computed: {
     pages: function () {
     return this.getPage(this.cur, this.totalPage, this.perSize);
     }
     }
     }
    </script>
    
    <style>
     ul, li {
     margin: 0px;
     padding: 0px;
     }
    
     li {
     list-style: none;
     display: inline;
     }
    
     .page-bar li:first-child > a {
     margin-left: 0px
     }
    
     .page-bar a {
     border: 1px solid #ddd;
     text-decoration: none;
     position: relative;
     float: left;
     padding: 6px 12px;
     margin-left: -1px;
     line-height: 1.42857143;
     color: #337ab7;
     cursor: pointer;
     }
    
     .page-bar a:hover {
     background-color: #eee;
     }
    
     .page-bar .active a {
     color: #fff;
     cursor: default;
     background-color: #337ab7;
     border-color: #337ab7;
     }
    
     .page-bar i {
     font-style: normal;
     color: #d44950;
     margin: 0px 4px;
     font-size: 12px;
     }
    
     .page-bar .page-con, .page-size {
     width: 50%;
     display: block;
     height: 30px;
     float: left;
     line-height: 30px;
     }
    
     .page-bar .page-con ul {
     float: right;
     padding-left: 15px;
     padding-right: 15px;
     display: inline-block;
     padding-left: 0;
     }
    
     .page-bar .page-size div {
     padding-left: 15px;
     padding-right: 15px;
     font-size: 14px;
     }
    
     a.disabled {
     color: #777;
     background-color: #fff;
     border-color: #ddd;
     cursor: not-allowed;
     }
    
     a.disabled:hover {
     background-color: #fff;
     }
    
     .clear-both {
     clear: both;
     }
    
     select {
     border: solid 1px #ddd;
     appearance: none;
     -moz-appearance: none;
     -webkit-appearance: none;
     background: url("../assets/images/arrow.png") no-repeat scroll right center transparent;
     padding-right: 15px;
     padding-left: 15px;
     padding-top: 2px;
     padding-bottom: 2px;
     }
    
     select::-ms-expand {
     display: none;
     }
    </style>
    End www.512Pic.com

    組建模塊使用, 

    代碼如下:

    <template>
     <Navbar></Navbar>
     <div class="row">
     <table class="table">
     <thead>
     <tr>
     <th>標(biāo)題</th>
     <th width="20%">發(fā)布時(shí)間</th>
     <th width="10%">作者</th>
     <th width="10%">回復(fù)數(shù)</th>
     <th width="10%">訪問(wèn)數(shù)</th>
     </tr>
     </thead>
     <tbody>
     <tr v-show="!tabelEmpty" v-for="item in dataList">
     <td>{{item.title}}</td>
     <td>{{item.create_at}}</td>
     <td>{{item.author.loginname}}</td>
     <td>{{item.reply_count}}</td>
     <td>{{item.visit_count}}</td>
     </tr>
     <tr v-show="tabelEmpty" class="empty">
     <td colspan="5">沒(méi)有匹配的記錄</td>
     </tr>
     </tbody>
     </table>
     </div>
     <Pagebar :page-model="pageModel"></Pagebar>
    </template>
    <script>
     import Navbar from '../components/navbar.vue'
     import Pagebar from '../components/table-pagebar.vue'
    
     export default {//這里是官方的寫法,默認(rèn)導(dǎo)出,ES6
     components: {
     Navbar,
     Pagebar
     },
     data () {
     return {
     allArticle: "",
     dataList: [],
     pageModel: {
     url: 'https:///api/v1/topics',
     menu: [5, 10, 20]
     },
     }
     },
     computed: {
     tabelEmpty: function () {
     if (this.dataList) {
     return false;
     } else {
     return true;
     }
     }
     },
     events: {
     refresh: function (e) {
     this.dataList = e;
     }
     }
     }
    </script>
    <style>
     body, table {
     font-size: 12px;
     }
    
     table {
     ;
     empty-cells: show;
     border-collapse: collapse;
     width: 100%;
     margin: 10px 0;
     }
    
     td {
     height: 30px;
     }
    
     div.row {
     margin-left: 15px;
     margin-right: 15px;
     }
    
     h1, h2, h3 {
     font-size: 12px;
     margin: 0;
     padding: 0;
     }
    
     .table {
     border: 1px solid #ddd;
     background: #fff;
     }
    
     .table thead tr {
     background: #eee;
     }
    
     .table th {
     background-repeat: repeat-x;
     height: 30px;
     text-align: left;
     vertical-align: middle;
     }
    
     .table tr.empty {
     text-align: center;
     }
    
     .table td, .table th {
     border: 1px solid #ddd;
     padding: 0 1em 0;
     }
    
     .table tr:nth-child(odd) td {
     background-color: #f5f5f5;
    
     }
    </style>
    End www.512Pic.com

    注:關(guān)于vue分頁(yè)組件table-pagebar使用入門實(shí)例的內(nèi)容就先介紹到這里,更多相關(guān)文章的可以留意512筆記的其他信息。

    關(guān)鍵詞:vue.js

      本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
      轉(zhuǎn)藏 分享 獻(xiàn)花(0

      0條評(píng)論

      發(fā)表

      請(qǐng)遵守用戶 評(píng)論公約

      類似文章 更多

      主站蜘蛛池模板: 国产偷窥熟女高潮精品视频| 亚洲精品色午夜无码专区日韩| AV极品无码专区亚洲AV| 国产中文字幕精品在线| 精品久久人人做爽综合| 亚洲欧美日韩成人综合一区| 国产乱妇乱子在线视频| 亚洲国产精品久久久久久久| 无码人妻一区二区三区精品视频| 亚洲 一区二区 在线| 久久月本道色综合久久| 亚洲AV无码专区亚洲AV桃 | 国产不卡在线一区二区| 午夜成年男人免费网站| 国内精品久久久久影院优| 午夜免费福利小电影| 亚洲AV无码精品色午夜果冻| 成 年 人 黄 色 大 片大 全| 国产亚洲国产精品二区| 久久综合色一综合色88| 老司机午夜精品视频资源| 亚洲日韩欧美一区二区三区| 日韩V欧美V中文在线| 在线观看免费人成视频播放| 男女猛烈无遮挡免费视频APP| 亚洲国产精品福利片在线观看| 亚洲国产精品午夜福利| 欧美牲交A欧美牲交| 国产成人高清精品亚洲| 日韩精品人妻av一区二区三区| 久久精品国产亚洲AV高清热| 欧美韩中文精品有码视频在线| 久久午夜无码免费| 97精品国产一区二区三区 | 精品一区二区不卡无码AV| 亚洲精品国产免费av| 亚洲AV永久无码精品三区在线 | 国产高清色高清在线观看 | 华人在线亚洲欧美精品| 大陆精大陆国产国语精品| 无码人妻久久一区二区三区APP |