注意:需要先在微信公众平台后台里添加request合法域名,还有必须用http

index.wxml

<view>
    <text>{{name}}</text>
</view>

index.js

onLoad:function(options){
 //页面加载完成之后,发送请求获取json数据,options为页面跳转所带来的参数
 var that = this;
 wx.request({
   url: '接口地址',
   method: 'get',
   dataType: 'json',
   success:function(res){
     console.log(res.data);
     that.setData({
       name: res.data.name
     })
   }
 })
},

发表回复

后才能评论