微信小程序ajax请求数据及一些方法

<viewclass="flex-wrp"style="flex-direction:row;"wx:for="{{Industry}}">
<viewclass="flex-item bc_green">
({{index}}){{item.date}} {{item.high}} {{item.low}}
{{item.notice}}
</view>
</view>
 
<viewclass="tip"hidden="{{isshow}}">数据加载完成</view>

js

// pages/list/list.js
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    Industry:{},
    isshow:true
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (res) {
    var that = this 
    wx.request({
      url: 'http://www.sojson.com/open/api/weather/json.shtml?city=杭州', 
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data.data.forecast)
        that.setData({
          Industry: res.data.data.forecast
        })  
      },
      fail: function () {
       console.log("fail")
      },
      complete: function () {
         that.setData({
           isshow:false
         })
      } 
    })
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
原文地址:https://www.cnblogs.com/zyfeng/p/11375449.html