es7 async await 报错
用 async await 报错 !
let getSid = function (){
let result = new Promise();
let sid = sessionStorage.getItem('sid');
if (!sid) {
axios({
method: "post",
url: COMMON_URL + '/app/init',
}).then(function(res) {
sessionStorage.setItem('sid', res.data.sid);
sid = res.data.sid;
result.resolve(sid)
});
}else{
result.resolve(sid)
}
return result;
}
export async function axiosPost (url, data) {
await getSid()
data = qs.stringify(data)
let result;
let token = sessionStorage.getItem('token');
let sid = sessionStorage.getItem('sid');
if (token == null) {
let isIngnore = location.pathname.indexOf(ingnoreRoute);
if (isIngnore < 0) {
location.href = '/account/login';
}
}
result = axios({
method: "post",
data: data,
url: COMMON_URL + url,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-SID': sid,
'X-TOKEN': token,
},
})
return result;
}
自问自答,经常用then 但很少new Promise 参数传错了 - -