封装wx.request同步
//wx.request同步方法
apiRequest:function(requrl,data){
return new Promise(function(resolve){
wx.request({
url: requrl,
data:data,
method:'POST',//按自己需求更改
header: {
'content-type': 'application/json' //默认值
},
success: function(res){//成功回调
resolve(res.data);
},
complete: function(res){//成功、失败都会执行
resolve(res.data);
}
})
})
},
//调用方法
//页面首次渲染完毕后触发
onReady: function () {
var that=this;
var data={};
that.apiRequest('https://www.daidu.com',data).then(function(result){
console.log(result);
})
},