飞狐爷

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  /**
   * 页面的初始数据
   */
  data: {
    goodslist: [
      { "url": "", "tit": "test01", "add_time": "2017" },
      { "url": "", "tit": "test02", "add_time": "2018" },
      { "url": "", "tit": "test03", "add_time": "2019" },
      { "url": "", "tit": "test04", "add_time": "2020" },
      { "url": "", "tit": "test05", "add_time": "2021" },
      { "url": "", "tit": "test06", "add_time": "2022" }
    ]
  },
/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中'
    })
    var that = this
    var header = {
      'content-type': 'application/x-www-form-urlencoded', 
      'Cookie': 'ECS_ID=' + wx.getStorageSync('session_id')
    }
    wx.request({
      url: app.globalData.requestUrl,
      header: header,
      success: function (res) {
        //console.log(res)
      }
    })
  },
/**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '加载中'
    })
    var that = this
    var goodslist = this.data.goodslist
    wx.request({
      url: app.globalData.requestUrl2,
      success: function (res) {
        for(var i=0; i<res.data.length; i++){
            goodslist.push(res.data[i])
        }
        that.setData({goodslist:goodslist})
        wx.hideLoading();
      }
    })
  },

 

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '数据加载中..',
    })
    var that = this
    that.data.page++
    var header = { 'content-type': 'application/x-www-form-urlencoded', 'Cookie': 'ECS_ID=' + wx.getStorageSync('ECSsession') }
    wx.request({
      url: app.globalData.requestUrl_category,
      method: "POST",
      header: header,
      data: {
        'page': that.data.page,
        'pagesize': that.data.pagesize
      },
      success: function (res) {
        if (res.data.error) {
          wx.hideLoading()
          wx.showToast({
            title: '加载完毕。',
          })
        } else {
          var mygoods = that.data.goodslist
          for (var i = 0; i < res.data.list.length; i++) {
            mygoods.push(res.data.list[i])
          }
          that.setData({
            goodslist: mygoods
          })
          console.log(res.data.page)
          console.log(res.data.list)
          wx.hideLoading()
        }
      }
    })
  },
  toast: function () {
    wx.showToast({
      title: 'okok',
      image: '/images/toast.png',
      icon: 'none'
    })
  }
<button bindtap='sp'>member/index</button>
<view wx:for="{{goodslist}}" class='gl' wx:for-item="row">
<view class='img'><image src="{{row.goods_thumb}}" mode="aspectFit" bindtap='toast'></image></view>
<view class='tit'>{{row.goods_name}}{{key}}</view>
<view class='cr'></view>
</view>

 

posted on 2018-02-06 09:40  飞狐爷  阅读(201)  评论(0编辑  收藏  举报