uni-app插件mescroll-uni使用問題

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

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

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

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

今天發(fā)現(xiàn)了一個問題就是使用mescroll-uni我沒有初始化,導(dǎo)致不能正常的上拉加載。。。

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,
      
      // 請求參數(shù)
      params: { page: 0 }
    }
  },
  components: { goodList },
  methods: {
    // 加載數(shù)據(jù)
    loadData () {
      let url = 'xxxxxxxxxx'
      
      // 封裝的請求函數(shù)
      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 = []
          }
          
          // 添加數(shù)據(jù)
          this.dataList = this.dataList.concat(res.data.list)
        } else {
          this.mescroll.endErr()
        }
      }))
    },

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

親測沒有問題
參考資料:http://www.mescroll.com/uni.html#custom

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容