微信小程式request請求後臺介面php的介紹
微信小程式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>