<template>
<mescroll-vue
ref="mescroll"
:down="mescrollDown"
:up="mescrollUp"
@init="mescrollInit"
>
<div id="mecroll_dataList">
<slot></slot>
</div>
</mescroll-vue>
</template>
<script>
import MescrollVue from "mescroll.js/mescroll.vue";
export default {
name: "mescrollComponent",
components: {
MescrollVue,
},
data() {
return {
mescroll: null,
mescrollDown: {
callback: this.downCallback,
},
mescrollUp: {
htmlLoading: '<p class="upwarp-progress mescroll-rotate"></p><p class="upwarp-tip">加载中..</p>',
htmlNodata: '<p class="upwarp-nodata">更多精彩敬请期待</p>',
callback: this.upCallback,
page: {
num: 1,
size: 10,
},
noMoreSize: 5,
toTop: {
src: "./static/mescroll/mescroll-totop.png",
},
empty: {
warpId: "mecroll_dataList",
icon: "./static/mescroll/mescroll-empty.png",
tip: "暂无相关数据~",
btntext: "去逛逛 >",
btnClick() {
alert("点击了按钮,具体逻辑自行实现");
},
},
lazyLoad: {
use: true,
},
},
};
},
methods: {
mescrollInit(mescroll) {
this.mescroll = mescroll;
},
upCallback(page, mescroll) {
this.$emit("load", page, mescroll);
},
downCallback(mescroll) {
this.$emit("downCallback", mescroll);
},
},
beforeRouteEnter(to, from, next) {
next((vm) => {
vm.$refs.mescroll && vm.$refs.mescroll.beforeRouteEnter();
});
},
beforeRouteLeave(to, from, next) {
this.$refs.mescroll && this.$refs.mescroll.beforeRouteLeave();
next();
},
};
</script>
<style scoped>
</style>
<template>
<div class="betterScrollBox">
<div class="top">
顶部
</div>
<div class="center">
<Mescroll ref="myscroll" @downCallback="downCallback" @load="getList">
<ul>
<li v-for="item in dataList" :key="item">
{{item}}
</li>
</ul>
</Mescroll>
</div>
<div class="bottom">
底部区域
</div>
</div>
</template>
<script>
import Mescroll from './../components/mescroll'
export default {
data () {
return {
dataList:[],
pageNo:1,
mescroll:null,
total:0
}
},
components:{
Mescroll
},
computed:{
searchParmas(){
const {pageNo} = this
return {
pageNo,
pageSize:10
}
}
},
mounted(){
},
methods:{
getList(page,mescroll){
this.pageNo = page.num
if(!this.mescroll){
this.mescroll = mescroll
}
setTimeout(()=>{
const {pageNo} = this
if(pageNo === 1){
this.dataList = []
}
let backList = []
let lastData = this.dataList.length
for (let index = lastData; index < lastData+10; index++) {
backList.push(index)
}
this.dataList = this.dataList.concat(backList)
this.$nextTick(()=>{
this.mescroll.endSuccess(backList.length,this.dataList.length < 13)
})
},1000)
},
downCallback(mescroll){
this.pageNo = 1
mescroll.resetUpScroll()
},
changeTab(){
this.pageNo = 1
this.dataList = []
this.mescroll.resetUpScroll()
}
}
}
</script>
<style scoped>
ul li{
padding: 20px 0;
text-align: center;
}
.betterScrollBox .top{
height: 44px;
border-bottom: 1px solid #ccc;
text-align: center;
line-height: 44px;
background: #fff;
position: fixed;
top: 0;
width: 100%;
z-index: 111;
}
.betterScrollBox .center{
position: fixed;
top: 44px;
width: 100%;
bottom: 50px;
}
.bottom{
position: fixed;
bottom: 0;
height: 50px;
width: 100%;
background: forestgreen;
text-align: center;
line-height: 50px;
color: #fff;
}
</style>