// pages/user/comment.js import api from '../../utils/api.js' import util from '../../utils/util.js' Page({ /** * 页面的初始数据 */ data: { commentParams: { page: 1, offset: 10 }, commentlist: [], commentCount: 0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getComemntData() }, getComemntData: function () { api.getMyGameCommentList(this.data.commentParams).then(res => { if (res.code === 200) { res.data.list.forEach((item, ids) => { item.create_time = util.formatTime(item.create_time, 'yyyy/MM/dd hh:mm') }) this.setData({ commentlist: this.data.commentlist.concat(res.data.list), commentCount: res.data.count || 0 }) } }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (this.data.commentCount <= this.data.commentlist.length) { return false; } this.data.commentParams.page = ++this.data.commentParams.page this.setData({ commentParams: this.data.commentParams }) this.getComemntData() } })