引入:
import ‘mint-ui/lib/style.css’
import { Toast,MessageBox,InfiniteScroll,Loadmore,Spinner } from ‘mint-ui’;
Vue.component(Toast);
Vue.component(MessageBox);
Vue.component(InfiniteScroll);
Vue.component(Loadmore.name,Loadmore);
Vue.component(Spinner.name, Spinner);
window.Toast= Toast;
window.MessageBox= MessageBox;
window.InfiniteScroll= InfiniteScroll;
import { Loadmore } from "mint-ui";
data() {
return {
list: [],
//可以进行上拉
allLoaded: false,
//是否自动触发上拉函数
isAutoFill: false,
wrapperHeight: 0,
courrentPage: 0
};
},
created() {
this.loadFrist();
this.loadMore();
},
mounted() { // 父控件要加上高度,否则会出现上拉不动的情况 this.wrapperHeight = document.documentElement.clientHeight - this.$refs.wrapper.getBoundingClientRect().top; var _this = this; axios .post(‘api’
, {
})
.then(function(data) {
if (data.status == 200) {
_this.list = data.data.resources.doc
}
});
// 下拉刷新
loadTop() {
this.loadFrist();
},
// 下拉刷新加载
loadFrist() {
this.$http
.post(`http://www.zhuangduoduo.net:3000/v1/pile/list`, {
topModelId: "2",
page: 1,
size: 10
})
.then(response => {
this.courrentPage = 0;
this.allLoaded = false; // 可以进行上拉
this.list = response.data.resources.doc;
this.$refs.loadmore.onTopLoaded();
});
},
// 上拉加载
loadBottom() {
this.loadMore();
},
// 加载更多
loadMore() {
this.$http
.post(`http://www.zhuangduoduo.net:3000/v1/pile/list`, {
topModelId: "2",
page: 1,
size: 10 * this.pageNum++
})
.then(response => {
// concat数组的追加
this.list = response.data.resources.doc
if (this.courrentPage > response.data.resources.total / 20) {
this.allLoaded = true; // 若数据已全部获取完毕
}
this.courrentPage++;
this.$refs.loadmore.onBottomLoaded();
});