Vue.prototype.$request = (url, mmethod,data, ok, failing, errorFun) => { axios({ method:"post", url: process.env.VUE_APP_BASE_API, headers: { 'Authorization': 'Basic eWljaHVuLWRhbmdqaWFuLWFkbWluOmJkOGQxZGM3N2JmMTVjMmY5OThiODFkZGUxMDI2Y2Y5', 'blossom-auth': window.localStorage.getItem(tokenKey) }, data: data, timeout: 100000, withCredentials: true }) .then(res => { console.log(res); switch (res.status) { case 200: if(res.data.reqcode!=undefined && res.data.reqcode==500){ localStorage.removeItem("token"); location.reload(); }else { if (url.substr(0, 5) == "login" && url != "logininfo") { localStorage.setItem("token", res.headers.token); localStorage.setItem("suuid", res.headers.suuid); if (ok) ok({code: "200", msg: "登录成功!"}); } else { if (ok) ok(res.data); } } break; default: if (ok) ok(res.data); break; } }) .catch(error => { if (errorFun) errorFun(error) else { if(error=='Error: Request failed with status code 500') { } } }); };
axios的全局使用
最新推荐文章于 2024-06-29 00:40:34 发布