小程序上拉加載的時候,數據請求下來之后會發現數據不會自動疊加,而是一個頁面只展示你所請求的數據,所以你要在此把每次請求的數據用concat連接起來,千萬不能用push添加,直接上代碼
data: { //全局變量
list:'',
title:'',
id:'',
currentPage:'1',
hasmore:false
}
onReachBottom() { //上拉觸底函數 let that = this //注意that console.log(that.data.id) console.log(that.data.currentPage++) console.log(that.data.list) wx.request({ url: 'http://www.zhm365.com/zhm/api/loadNewByTitle', data: { title:that.data.id, pageSize: '10', currentPage:that.data.currentPage++ // 請求頁面不能定死,每次請求頁面自增,如果頁面固定死的話,每次請求的數據相同 }, method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { console.log(res.data.info) if(res.data.info!==null){ //每次刷新的數據疊加,注意是用concat進行連接,而不是用push添加 that.setData({ list: that.data.list.concat(res.data.info), hasmore: true }) }else{ that.setData({ hasmore: true }) } } }) },