微信小程序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>

这里写图片描述

转载原文地址

猜你喜欢

转载自blog.csdn.net/zhongshijun521/article/details/80584700