微信小程序request請求后臺接口php的實例詳解
后臺php接口:http://www.vueyun.com/good/info
沒有處理數據,直接返回了,具體再根據返回格式處理
public function getGoodInfo(Request $request){ $goods_datas = $this->Resource->get(); return response()->json(['status' => 'success','code' => 200,'message' => '獲取成功','data'=>$goods_datas]);}小程序index.js文件中 onLoad
onLoad: function () { console.log('onLoad') wx.request({ //上線接口地址要是https測試可以使用http接口方式 url: 'http://www.vueyun.com/good/info', data: {}, method: 'GET', header: { 'content-type': 'application/json' }, success: function (res) { that.setData({ goodslist: res.data.data }); console.log(res.data.data, 1111111); }, }) },wxml文件,
<view class="goods-container"> <block wx:for="{{goodslist}}" wx:for-item="item" wx:for-index="idx" > <view class="goods-box" bindtap="goodsTap" data-id="{{item.id}}"> <view class="img-box"> <image src="{{item.img_url}}" class="image"/> </view> <view class="goods-title">{{item.img_title}}</view> <view class="goods-price">¥ {{item.good_price}}</view> </view> </block> </view>如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答