1. 程式人生 > >微信小程式系列三:資料獲取及資料渲染

微信小程式系列三:資料獲取及資料渲染

1.資料獲取:

注意:

      1.伺服器地址要配置https

      2.配置合法域名

      3.本地除錯記得在開發者工具勾選

wx.request({
   url: '介面地址',
   data: {},
   success: function (res) {},
   fail:function(err){}
})

2.資料渲染:

  js程式碼如下:

onLoad: function (options) {
  var that=this;
    wx.request({
      url: 'https://xxxxxxx',
      data: {},--引數
      success: function (res) {
       that.setData({
          shuju:res.xxxxx
       })
      },
      fail: function (err) {
        //失敗執行
      }
    })    
}

頁面渲染:

<block wx:for="{{shuju}}">
    <view>{{item.xxx}}</view>
</block>