使用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