const app = getApp(); Component({ properties: { }, data: { shixuns:[] }, pageLifetimes: { show(){ app.syncUser() .then(res=>{ if(res.user.user_id!=this.user_id){ this.pullShixuns({refresh:1}); this.user_id = res.user.user_id; } }) } }, attached(){ this.options = {page:1, per_page:16}; app.syncUser() .then(res => { if (res.user.user_id != this.user_id) { this.pullShixuns({ refresh: 1 }); this.user_id = res.user.user_id; } }); }, methods: { async pullShixuns({refresh=0}={}){ if(refresh){ if(refresh==1){ this.options.page = 1; var { options } = this; }else if(refresh==2){ var {page, per_page} = this.options; var options = {page:1, per_page: page*per_page}; } }else{ this.options.page++; var {options} = this; }let {shixuns} = await app.api("users.shixuns")(options); if(!refresh) shixuns = this.data.shixuns.concat(shixuns); this.setData({shixuns}); return shixuns; }, onPullDownRefresh(){ this.pullShixuns({refresh:2}); }, onReachBottom(){ this.pullShixuns({refresh:0}); } } })