This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import axios from "axios";
const req = axios.create({
baseURL: "http://localhost:3000",
timeout: 2000
})
// 添加请求拦截器
req.interceptors.request.use(function (config) {
// 在发送请求之前做些什么
if (localStorage.getItem("token")) {
//有token,则默认发送给服务器
config.headers.Authorization = `Bearer ${localStorage.getItem("token")}`
}
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
export default req