new Vue({ el: '#app', data() { return { proarr: [], showLoading: false, p:1, errmsg:'' }; }, components: { }, created() { this.getProList(); //监听滚动 window.addEventListener('scroll', this.handleScroll); }, methods: { handleScroll() { //判断滚动到底部 if ($(window).scrollTop() >=$(document).height() - $(window).height()) { this.showLoading = true; this.p++; this.getProList(this.p); } }, getProList() { var that = this; $.post('url',{p:this.p},function(datas){ var state = datas.sign; that.showLoading = false; if (state === ERROK) { var data = datas.data.data; for (var i = 0; i < data.length; i++) { that.proarr.push(data[i]); } that.errmsg=''; } else { that.errmsg='暂无更多数据'; } },'json'); } }})
开始碰到个坑。请求到的数据我直接push到循环数组中,结果整个数组变成一个元素,后来想了想用循环把每一条数据分别push才解决这个问题