欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實現(xiàn)一個簡單的分頁功能實例詳解

 更新時間:2022年12月24日 15:18:03   作者:約妲己吃火鍋  
這篇文章主要介紹了vue實現(xiàn)一個簡單的分頁功能,需要的朋友可以參考下

這是一個簡單的分頁功能,只能夠前端使用,數(shù)據(jù)不能通過后臺服務(wù)器進行更改,能容已經(jīng)寫死了。

下面的內(nèi)容我是在做一個關(guān)于婚紗項目中用到的,當(dāng)時好久沒用vue了,就上網(wǎng)區(qū)找了別人的博客來看,發(fā)現(xiàn)只有關(guān)于element_ui的,基本全是,對自己沒用什么用,就自己寫了一個,效果如下:

在這里插入圖片描述

點擊相應(yīng)的按鈕切換到對應(yīng)的內(nèi)容內(nèi)容:

在這里插入圖片描述

下面我只發(fā)核心代碼,css樣式就不發(fā)了,自己想怎么寫怎么寫

 <!-- 分頁內(nèi)容 -->
          <ul class="blog-lists-box">
             <li class="blog-list" :key="index" v-for="(item, index) in dataShow" :class="{ 'alt': index%2 == 1 }">
                <div class="card">
                    <div class="blog-overlay">
                      <router-link to="/blog/singleBlog">
                        <figure>
                          <img :src="img1"/>
                          <figcaption></figcaption>
                        </figure>
                      </router-link>
                    </div>
                    <div class="card-body">
                       <router-link to="/blog/singleBlog">
                         <h4 class="card-title">{{item.title}}</h4>
                       </router-link>
                       <div class="card-footer">
                         <div class="card-footer-box d-flex">
                           <div class="author-box">
                             <a href="#" rel="external nofollow" >
                               <img :src="header1"/>
                               <span>{{item.username}}</span>
                             </a>
                           </div>
                           <div class="blog-date text-uppercase">
                             <i class="fa fa-calendar"></i>
                             <span>{{item.time}}</span>
                           </div>
                         </div>
                       </div>
                    </div>
                </div>
              </li>
          </ul>
          <!-- 分頁按鈕組 -->
          <div class="page">
             <ul class="pagination clearfix flex-center">
                <li class="page-item stic">
                   <a class="page-link "  v-on:click="prePage">Prev</a>
                </li>
                <li class="page-item" :key="index" v-for="(item, index) in totalPage">
                   <a class="page-link"  v-on:click="toPage(index)" :class="{active: currentPage == index}">{{ index+1 }}</a>
                </li>
                <li class="page-item">
                   <a class="page-link"  v-on:click="nextPage">Next</a>
                </li>
             </ul>
          </div>

下面是vuejs代碼可能有點多,但是沒關(guān)系,這個會了,以后遇到直接就可以拿來用了

 data () {
    return {
      img1: img1,
      header1: header1,
      listArray: [{
        'title': '25 Places To Get The Best Wedding...',
        'username': 'liulong',
        'time': '2019/12/6'
      }, {
        'title': '10 Bridal Bouquets You'll Fall In Love...',
        'username': 'wangxianhui',
        'time': '2019/12/7'
      }, {
        'title': 'Tips For Choosing The Right Weddi...',
        'username': 'chenggang',
        'time': '2019/12/8'
      }, {
        'title': 'Planning The Perfect Bachelorette...',
        'username': 'wangwengang',
        'time': '2019/12/9'
      }, {
        'title': 'Top 20 Tips for Wedding Invitat...',
        'username': 'yuzhiwei',
        'time': '2019/12/10'
      }, {
        'title': 'Best Tips for the Bride and Groom...',
        'username': 'zhaopu',
        'time': '2019/12/11'
      }],
      // 控制每頁顯示數(shù)據(jù)的數(shù)數(shù)量
      pageSize: 3,
      // 默認顯示第幾頁
      currentPage: 0,
      // 總數(shù)據(jù)
      totalPage: [],
      // 當(dāng)前顯示的數(shù)據(jù)
      dataShow: []
    }
  },
  methods: {
    nextPage: function () {
      if (this.currentPage === this.pageNum - 1) {
        return
      }
      this.dataShow = this.totalPage[++this.currentPage]
    },
    prePage: function () {
      if (this.currentPage === 0) {
        return
      }
      this.dataShow = this.totalPage[--this.currentPage]
    },
    toPage: function (page) {
      this.currentPage = page
      this.dataShow = this.totalPage[this.currentPage]
    }
  },
  created: function () {
    this.pageNum = Math.ceil(this.listArray.length / this.pageSize) || 1
    for (var i = 0; i < this.pageNum; i++) {
      this.totalPage[i] = this.listArray.slice(this.pageSize * i, this.pageSize * (i + 1))
    }
    this.dataShow = this.totalPage[this.currentPage]
  }

以上就是vue實現(xiàn)一個簡單的分頁功能的詳細內(nèi)容,更多關(guān)于vue實現(xiàn)一個簡單的分頁功能的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論