uni-app插件mescroll-uni使用问题

使用mescroll-uni一定要初始化。

使用mescroll-uni一定要初始化。

使用mescroll-uni一定要初始化。

重要的事情只说三遍。。。

今天发现了一个问题就是使用mescroll-uni我没有初始化,导致不能正常的上拉加载。。。

mescroll-uni简单使用代码

html代码块
<mescroll-body
  ref="mescrollRef"
  :down="down"
  :height="bodyH"
  bottombar="false"
  safearea="true"
  @init="initCallback"
  @up="upCallback"
  @down="downCallback">
  <view class="content-list">
    <!-- 商品列表 -->
    <good-list :list="dataList"></good-list>
  </view>
</mescroll-body>
js代码块
<script>
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js"
import goodList from "@/components/common/goodList"

export default {
  mixins: [MescrollMixin],
  data () {
    return {
      dataList: [],
      down: {
        auto: false,
        mustToTop: true
      },
      bodyH: '0',
      mescroll: null,
      
      // 请求参数
      params: { page: 0 }
    }
  },
  components: { goodList },
  methods: {
    // 加载数据
    loadData () {
      let url = 'xxxxxxxxxx'
      
      // 封装的请求函数
      this.$request.get(url, this.params, (res => {
        if (res.code === 200) {
          let moreFlag = true
          if (res.data.total <= this.dataList.length) {
            moreFlag = false
          }

          this.mescroll.endSuccess(res.data.list.length, moreFlag)

          if (this.params.page === 1) {
            this.dataList = []
          }
          
          // 添加数据
          this.dataList = this.dataList.concat(res.data.list)
        } else {
          this.mescroll.endErr()
        }
      }))
    },

    // 初始化回调
    initCallback (ele) {
      if (this.mescroll === null) this.mescroll = ele
    },
      
    // 下拉回调
    downCallback (e) {
      console.log("下拉")
      this.params.page = 1
      this.loadData()
    },
       
    // 上拉回调
    upCallback (e) {
      console.log("上拉")
      this.params.page++
      this.loadData()
    }
  }
}
</script>

亲测没有问题
参考资料:http://www.mescroll.com/uni.html#custom

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容