1. 程式人生 > >vue.js 列表資料載入更多

vue.js 列表資料載入更多

<template>
  <div>
  <!--header-->
  <com-header :title="headerData.title" :toLink="headerData.toLink"></com-header>
  <!--header end-->


  <!--container-->
<div>
<a class="mint-cell">
<div class="mint-cell-wrapper">
<div class="mint-cell-title">
<div class="hhxh-flex">
<div class="flex-0 text-center w-25 gray">時間</div>
<div class="flex-0 text-center w-25 gray">使用者名稱</div>
<div class="flex-0 text-center w-10 gray">型別</div>
<div class="flex-0 text-center w-20 gray">增值量</div>
<div class="flex-0 text-center w-20 gray">提成</div>
</div>
</div>
</div>
</a>
</div>
<div class="myproperty-achievement-box" style="top: 87px">
<div class="container1-box">
<div>
<mt-loadmore :bottom-method="loadMore" :bottom-all-loaded="allLoaded" ref="loadmore" :auto-fill=false >
<a class="mint-cell" v-for="item in items">
<div class="mint-cell-wrapper">
<div class="mint-cell-title">
<div class="hhxh-flex">
<div class="flex-0 text-center w-25">{{dateFormat(item.bizDate)}}</div>
<div class="flex-0 text-center w-25">{{item.userName}}</div>
<div class="flex-0 text-center w-10">{{item.type}}</div>
<div class="flex-0 text-center w-20">{{item.inreaseAmount}}</div>
<div class="flex-0 text-center w-20">{{item.commission}}</div>
</div>
</div>
</div>
</a>
</mt-loadmore>
</div>
</div>
</div>
<no-data :items="items" :isLoading="isLoading"></no-data>
<!--container end-->


<!--footer-->


<!--fonter end-->
  </div>
</template>


<script>
import comHeader from 'components/comHeader'
import noData from 'components/noData'
import mineIncome from '../SERVICES/mineIncome'
export default {
  components: {
    comHeader,
    noData
  },
  data: () => ({
    headerData: {
      title: '測試',
      toLink: ''
    },
    isLoading: true,
    pageNo: 1,
    pageSize: 10,
    allLoaded: false,
    items: []
  }),
  created () {
    // 元件建立完後獲取資料,這裡和1.0不一樣,改成了這個樣子
    this.loadList()
  },
  methods: {
    loadList: function () {
      let bizDate = sessionStorage.getItem('bizDate')
      let startTime = bizDate + ' 00:00:00'
      let endTime = bizDate + ' 23:59:59'
      mineIncome.loadShareDetail(startTime, endTime, this.pageNo, this.pageSize).then(res => {
        this.isLoading = false
        let list = res.t
        if (list.length === 0) {
          // 若資料已全部獲取完畢,將繫結到元件bottom-all-loaded屬性的變數賦值為true,這樣bottom-method就不會再次執行了
          this.allLoaded = true
        } else if (list.length > 0 && list.length <= this.pageSize) {
          for (let i = 0; i <= list.length - 1; i++) {
            this.items.push(list[i])
          }
          if (list.length === this.pageSize) { // 長度達到每頁的最大長度,說明後面可能還有資料
            this.pageNo += 1
          } else { // 沒有更多的資料了
            this.allLoaded = true
          }
        }
      })
    },
    loadMore: function () {
      // 載入更多資料
      this.loadList()
      // 在載入資料後需要對元件進行重新定位的操作
      this.$refs.loadmore.onBottomLoaded()
    },
    dateFormat: function (date) {
      return window.moment(date).format('YYYY-MM-DD HH:mm:ss')
    }
  }
}
</script>