添加登录

This commit is contained in:
alger
2021-09-29 17:24:03 +08:00
parent e108059773
commit a7f1453609
10 changed files with 194 additions and 15 deletions
+24
View File
@@ -5,4 +5,28 @@ const request = axios.create({
timeout: 10000,
});
// 请求拦截器
request.interceptors.request.use(
(config) => {
// 在请求发送之前做一些处理
// 在get请求params中添加timestamp
if (config.method === "get") {
config.params = {
...config.params,
timestamp: Date.now(),
};
let token = localStorage.getItem("token");
if (token) {
config.params.cookie = token;
}
}
return config;
},
(error) => {
// 当请求异常时做一些处理
return Promise.reject(error);
}
);
export default request;