微信小程序request请求后台接口php简单实例

没有处理数据,直接返回了,具体再根据返回格式处理

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>

样式代码不写了 最终的结果是这样

这里写图片描述


https://www.vueyun.com

  • 6
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值