先在app.js中自定义一个函数 内容写自己需要传的数据,我这里需要的是用户的openid
参考
lc: function (wei) {
var that = this;
wx.login({
success: function (res) {
console.log(res.code)
//发送请求
wx.request({
url: 'http://127.0.0.1:9090/xcxmvc/pp/dl', //接口地址
data: { code: res.code },
header: {
'content-type': 'application/json' //默认值
},
success: function (res) {
c = "ff";
console.log(res.data)
that.globalData.openid = res.data.openid;
wei(res);
return wei;
}
})
}
})
console.log("c");
// this.ajax();//调用ajax函数
},
然后在app.js的onlaunch中调用这个函数
var wei = this.lc(function (wei) {
console.log(wei);
});
最后在需要获得数据的页面的onload中写
<