微信小程序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 () {
  
  }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM