微信小程序wx.request后台数据交互
Page({ data: { newsList:[] }, onLoad: function () { this.getData(); }, getData:function(){ var that = this; wx.request({ url: http://www.phonegap100.com/appapi.php?a=getPortalCate,//请求地址 header:{ "Content-Type": "applciation/json" }, method:GET, success:function(res){ console.log(res.data) that.setData({ newsList:res.data.result }) }, fail:function(err){ } }) } })
wxml页面: <view wx:for-items="{ { newsList}}" wx:key="id" class="list"> <view class=list-title>{ { item.catname}}</view> </view>
上一篇:
uniapp开发微信小程序-2.页面制作