vue是一种轻巧便捷的框架,那么如何进行对于数据加载的刷新呢?以下就是我对于vue.js数据加载的一点想法
源码:
加载中...
解析:
$(function() {
var pageNum = 1;
var pageSize = 6;
vue = new Vue({
el: '#app',
data: {
items: [],
pageNum: pageNum,
pageSize: pageSize,
rawItems: [],
sitems:[]
},
methods: {
getList: function() {
$.showLoading();
this.$http.get(store.list, {
pageNum: pageNum,
pageSize: pageSize
}).then(function(result) {
$.removeLoading();
this.sitems = result.data.data.items;
}, function() {
$.removeLoading();
$.showAlert({
'title': '提示',
'content': "页面偷懒了~~",
'sure': this.close
});
})
},
close: function() {
history.go(-1);
},
onScroll: function(event) {
var offsetHeight = event.currentTarget.offsetHeight,
scrollHeight = event.target.scrollHeight,
scrollTop = event.target.scrollTop,
scrollBottom = offsetHeight + scrollTop;
if(scrollBottom == scrollHeight+10 ||scrollBottom == scrollHeight) {
if(this.pageNum == Math.ceil(this.rawItems.length / this.pageSize)) {
return
}
this.pageNum++;
pageNum++;
$(".myload").removeClass("disn");
vue.$http.get(store.list, {
pageNum: pageNum,
pageSize: pageSize
}).then(function(result) {
setTimeout(function() {
$(".myload").addClass("disn");
vue.sitems = vue.sitems.concat(result.data.data.items);
}, 2000)
}, function() {
$(".myload").addClass("disn");
})
}
},
},
ready: function() {
this.getList();
for(var i = 0; i <= 1000; i++) {
this.rawItems.push(i)
}
}
})
})
以上是vue.js加载新的内容的详细内容。更多信息请关注PHP中文网其他相关文章!