mint ui 上拉加载


 

<template>
    <mt-loadmore :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" :auto-       fill="false" ref="loadmore" >

        <ul class="battle-details">

          <li class="details-li" v-for="battleList in historyData" :key="battleList.id"></li>

       </ul>

    </mt-loadmore>

</template>

<script>

export default {

data() {

     return {

            pageNo: 1,

            pageSize: 10,

            historyData: [], //每次加载累加后的总数据 

            allLoaded: false,   //若为真,则 bottomMethod 不会被再次触发

      }

},

methods: {

              //上拉加载

    loadBottom() {

                   this.$refs.loadmore.onBottomLoaded();

                   this.getBattleData();

              },

    getBattleData() {

              let request_data = {

                       "pageNow": this.pageNo,

                       "pageSize": this.pageSize

               };

this.$http.post("------------", request_data})

.then(res => {

     this.historyData = this.historyData.concat(res.data.data.list);   //合并每次请求的数组得到总的数据

     this.allLoaded = false;

     this.pageNo += 1;

 }

mounted() {

      this.$nextTick(() => {

              this.historyData = [];  //第一次进入数据为空,请求数据

              this.getBattleData();

     });



}

};

 

转载:https://blog.csdn.net/huangxiaoguo1/article/details/80163585

<template>
    <div class="main-body" ref="wrapper" :style="{ height: (wrapperHeight-50) + 'px' }">
      <mt-loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" ref="loadmore" :autoFill="isAutoFill">
        <ul class="mui-table-view mui-grid-view">
          <li v-for="(item,index) in datas" :key="index" class="mui-table-view-cell mui-media mui-col-xs-6">
            <a>
              <img class="mui-media-object" v-lazy="item.img">
              <div class="mui-media-body" v-text="item.title"></div>
            </a>
          </li>
        </ul>
      </mt-loadmore>
    </div>
</template>

<script>
export default {
  name: "goodslist",
  data() {
    return {
      datas: [],
      //可以进行上拉
      allLoaded: false,
      //是否自动触发上拉函数
      isAutoFill: false,
      wrapperHeight: 0,
      courrentPage: 0
    };
  },
  created() {
    this.loadFrist();
  },
  mounted() {
    // 父控件要加上高度,否则会出现上拉不动的情况
    this.wrapperHeight =
      document.documentElement.clientHeight -
      this.$refs.wrapper.getBoundingClientRect().top;
  },
  methods: {
    //   下拉刷新
    loadTop() {
      this.loadFrist();
    },
    // 上拉加载
    loadBottom() {
      this.loadMore();   //请求数据的方法
    },
    // 下来刷新加载
    loadFrist() {
      this.$axios
        .get("goodslist1.json")
        .then(response => {
          this.courrentPage = 0;
          this.allLoaded = false; // 可以进行上拉
          this.datas = response.data.message;
          this.$refs.loadmore.onTopLoaded();
        })
        .catch(error => {
          console.log(error);
          alert("网络错误,不能访问");
        });
    },
    // 加载更多请求数据
    loadMore() {
      this.$axios
        .get("goodslist.json")
        .then(response => {
          // concat数组的追加
          this.datas = this.datas.concat(response.data.message);
          if (this.courrentPage > 2) {
            this.allLoaded = true; // 若数据已全部获取完毕
          }
          this.courrentPage++;     //页码加1
          this.$refs.loadmore.onBottomLoaded();  
        })
        .catch(error => {
          console.log(error);
          alert("网络错误,不能访问");
        });
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.main-body {
  /* 加上这个才会有当数据充满整个屏幕,可以进行上拉加载更多的操作 */
  overflow: scroll;
}

 

 

</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值