const { api } = require("../../utils/api") // pages/community/index.js Page({ /** * 页面的初始数据 */ data: { page:{ current:0, pageSize:10 }, list:[] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, goAdd(){ const tmp = wx.getStorageSync('user') if (tmp.phone.length === 0){ wx.navigateTo({ url: '../login/index', }) return } wx.navigateTo({ url: '../community/add', }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, goInfo(e){ const id = e.currentTarget.dataset.id wx.navigateTo({ url: '../community/info?id=' +id, }) }, /** * 生命周期函数--监听页面显示 */ onShow() { this.fetchList() }, fetchList(){ const data = {...this.data.page} api('/post/page','POST',data,'json').then(res => { if (res.code === 200){ console.log(res.data); const tmps = res.data.list this.setData({list:tmps}) } }) }, like(e){ const {id,hasLiked} = e.currentTarget.dataset.item api( hasLiked === 1 ? '/post/cancelLike':'/post/like','GET',{id}).then(res => { if (res.code === 200){ this.fetchList() } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })