vue----mintui之上拉加载下拉刷新

1.注意点

   注意父级元素一定要设置高度(如果顶部底部有固定元素减去顶部底部元素的高度)  否者下拉刷新会存在问题

2.父级元素在css中加上该属性(-webkit-overflow-scrolling: touch;) 避免在IOS上存在问题

 

截图如下:

 

代码如下:


<template>
  <div>
    <div class="fixTop"></div>
    <div id="content"  v-bind:style="{'height': clientHeight-120 + 'px' }">
      <!-- <div id="content"  > -->
      <mt-loadmore
        class="loadmore"
        :top-method="loadTop"
        :bottom-method="loadBottom"
        :bottom-all-loaded="allLoaded"
        :auto-fill="false"
        ref="loadmore"
      >
        <!-- 页码为1时提示信息 -->
        <!-- v-bind:style="{'min-height': clientHeight-120 + 'px' }" -->

        <div class="wrap" v-bind:style="{'min-height': clientHeight-120 + 'px' }">
          <div class="item" v-for="(data,index) in list" :key="index"  >
            <div class="name">{{index}}</div>
          </div>
          <div v-show="allLoaded">没有更多</div>
        </div>
      </mt-loadmore>
    </div>

    <div class="fixBottom"></div>
  </div>
</template>

<script>
import { list, list2 } from "../fetch/api";
import { fetch } from "../fetch/fetch";

//默认会加载一次上拉
export default {
  data() {
    return {
      list: [],
      allLoaded: false,
      pageStart: 1,
      clientHeight: 0
    };
  },
  mounted: function() {
    this.getList(); //第一次的数据

    //原生获取屏幕高度
    this.clientHeight =
      document.documentElement.clientHeight || document.body.clientHeight;
    console.log(this.clientHeight);
  },

  activated() {
    //原生获取屏幕高度
    var h = document.documentElement.clientHeight || document.body.clientHeight;
    console.log(h);
  },

  watch: {
   
  },
  methods: {
    loadTop: function() {
      console.log("下拉");
      this.pageStart = 1;
      this.allLoaded = false;     // 可以进行上拉
      this.$refs.loadmore.onTopLoaded();
      this.getList();
    },
    loadBottom: function() {
      console.log("上拉");
      this.$refs.loadmore.onBottomLoaded();
      this.pageStart++;
      this.getList();
    },

    // 商品列表
    getList: function(done) {
      var that = this;
       list2({
       type:1,
       page:that.pageStart
      }).then(function(data) {
        console.log(data.data);
        var list = data.data;
        console.log("页码" + that.pageStart);
        if (that.pageStart == 1) {
          that.concatList = [];
        } else {
          that.concatList = that.list;
        }

        if (list.length < 10) {
          console.log("加载完毕到底了");
          that.allLoaded = true;   // 禁止上拉
        }

        that.list = list.concat(that.concatList);
      })
        
    }
  }
};
</script>

<style>
#content {
  width: 100%;
  overflow: scroll;
  overflow-y: scroll;
  background: pink;
  -webkit-overflow-scrolling: touch;
  position: relative;
  top: 50px;
  /* height: 500px; */
}

.item {
  width: 100%;
  height: 100px;
  margin-bottom: 0;
  background: #ccc;
  margin-bottom: 2px;
}

.wrap {
  /* min-height: 500px; */
}
.fixTop {
  width: 100%;
  height: 50px;
  background: red;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
.fixBottom {
  width: 100%;
  height: 50px;
  background: red;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 1000;
}
</style>






 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值