Home >Web Front-end >JS Tutorial >vue.js loads new content
Vue is a lightweight and convenient framework, so how to refresh the data loading? The following are my thoughts on vue.js data loading
Source code:
Loading...
Analysis:
$(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': 'Tips' ,
'content': "The page is lazy~~",
'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)
}
}
})
})
The above is the detailed content of vue.js loads new content. For more information, please follow other related articles on the PHP Chinese website!