var app = new Vue({ 'el': '#app', 'data': { // 列表数据 dataList: [], // 参数 params: { page: 1, pageSize: 6 }, loading: false, loaded: false, }, created: function(){ this.getDataList(0); }, mounted: function(){ var _this = this; $(window).scroll(function(){ var scrollHeight = $(this).scrollTop(); var height = $('body')[0].scrollHeight; var docHeight = $(this).outerHeight(); if(docHeight+scrollHeight >= height-1){ if(_this.loading || _this.loaded){ return false; } _this.params.page++; _this.getDataList(1); } }) }, methods: { // 详情 goDetail: function(id){ if(id){ location.href = '/weixin/goods/detail?id='+id; } }, // 获取列表数据 getDataList: function(more){ var _this = this; $.showLoading("数据加载中..."); _this.loading = true; $.post('/weixin/goods/goodsList', _this.params, function (res) { $.hideLoading(); _this.loading = false; if (res.code == 'success') { if(res.data.data.length<=0 && _this.params.page > 1){ _this.loaded = true; $.toast("已加载完全部...",'text'); return false; } if(more){ $.each(res.data.data, function(k,item){ _this.dataList.push(item); }); }else{ _this.dataList = res.data.data } }else if(res.code == 'login'){ login(res.data.url); } }, "json"); }, } })