mkhttp
v1.0.2
Published
A simple request tool encapsulated in axios
Downloads
13
Readme
安装
npm i mkhttp
使用例子
1.const http = new MkAxiosHttp({
//请求头配置
headers: {
"Content-Type": "application/json",
},
baseURL: "基础地址",
interceptors: {
// 请求前拦截器
// @param {Object} config 发送请求的配置
// @return {Object} 发送请求的配置
requestInterceptors(req) {
return req
},
requestInterceptorsCatch(err) {
return err
},
responseInterceptors: (res) => {
abortControllerMap.delete(res.config.url!);
return res.data
},
responseInterceptorsCatch: (res) => {
res.config && abortControllerMap.delete(res.config.abortRequestFlag!);
if (res?.response?.status == 403) {
let authStore = useAuthStore();
if( authStore.isLogged ){
window.naiveMessage.error("登录过期或该账号已在其他地方登录,请重新登录")
}
authStore.isLogged = false;
localCache.remove(TokenKey);
router.push("/login");
return Promise.reject();
}
if(res?.response?.status == 401){
window.naiveMessage.error("该账号暂无此权限")
return Promise.reject();
}
return Promise.reject(res.message)
},
}
})
一些调用方法
http.post() http.get() http.post() http.put()