在util.js中封装了请求
var rootDocment = 'https://xxxxxx';
function getreq(url,data,success,fail){
console.log(data) //获取不到token,能取到is_end
wx.showLoading({
title: '加载中',
})
wx.request({
url: rootDocment + url,
data:data,
header: {
'content-type': 'application/json' // 默认值
},
method:'post',
success(res) {
wx.hideLoading();
success(res.data);
},
fail(res){
fail()
}
})
}
然后在onload中传入了wx.getStorageSync
data{
parmas: [{
"mini_token": wx.getStorageSync('token'),
"is_end": 1
}]
}
onLoad: function(options) {
console.log( wx.getStorageSync('token')) //这个时候还能取到
http.getreq("/mini/UserActivity/oneGrab", that.data.parmas[0],
function(res) {
console.log(res)
}
)
}
在页面onload时发起请求之前能获取到token的值,在封装的请求里面就获取不到了