1. 程式人生 > >小程式request 請求使用

小程式request 請求使用

Page({

  /**    * 頁面的初始資料    */   data: {     baidu: null   },

  /**    * 生命週期函式--監聽頁面載入    */   onLoad: function (options) {     var refs = this;     wx.request({       url: 'https://zhidao.baidu.com/question/api/recommend?t=1532415684126',       method: "GET",       success: function (res) {        refs.setData({baidu: res.data})       },       fail: function () {         console.log("介面呼叫失敗");       }     })   }, })

<view>   <view style="margin-bottom: 30rpx" wx:for="{{ baidu.list }}" wx:key="{{ index }}">     <image src="{{ item.avatar }}" style="width:60rpx;height:60rpx;"></image>     <text style="font-size:37rpx">{{ item.uname }}:</text>     <text style="font-size:27rpx; color:#ccc;">{{ item.createTime }}</text>     <view>       <text>{{ item.title }}</text>     </view>   </view>   <view wx:for="{{ baidu.reward }}" wx:key="{{ index }}">     <image src="{{ item.imgUrl }}" style="width:100rpx;height:100rpx;"></image>   </view> </view>