悠悠楠杉
网站页面
注意:需要先在微信公众平台后台里添加request合法域名,还有必须用https
index.wxml
<view>
<text>{{name}}</text>
</view>
index.js
onLoad:function(options){
//页面加载完成之后,发送请求获取json数据,options为页面跳转所带来的参数
var that = this;
wx.request({
url: '接口地址',
method: 'get',
dataType: 'json',
data: {id: 1},
success:function(res){
console.log(res.data);
that.setData({
name: res.data.name
})
},
fail:function(){
console.log('请求失败');
}
})
}