// index.js // 获取应用实例 const app = getApp() const { axios } = app.globalData; Page({ data: { // 商品列表 shoplist: [], }, // 点击商品查看详情 ShopSuccess (e) { let { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/pages/detail/detail?data=${JSON.stringify({ id })}`, }) }, //加载商品数据 模拟5条 PageCount: 1,//总页数 Page: 1,//当前页数 ShopRequest () { if (this.Page > this.PageCount) return false; let that = this, { shoplist } = this.data; axios({ url: "/commodity/wx_commodity/", method: "get", data: { page: that.Page, limit: 10, }, success (res) { let { data, totalPage } = res.data; that.PageCount = totalPage; that.Page++; data.forEach(item => { shoplist.push({ id: item.id, price: item.amount, desc: item.introduce, imgurl: item.list_image, title: item.name }) }) wx.stopPullDownRefresh(); that.setData({ shoplist }) } }) }, onLoad () { wx.lxd.Ctr({ // nav title: "首页", //标题 back: false,//返回按钮,tabber必须false(除非会改) bgc: false,//使用更改后的颜色;配合json使用 // tabber tabber: true, // 显示 active: 0,//活动值 }) }, onShow () { this.ShopRequest(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.PageCount = 1; this.Page = 1; this.setData({ shoplist: [] }) this.ShopRequest(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.ShopRequest(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, onShareTimeline: function (res) { } })