赞
踩
- import axios from "axios";
- import testApi from "./mock";
- // const { VITE_BASE_URL } = import.meta.env; // vite 脚手架
-
- // 实例对象
- class HttpInstance {
- constructor(config, apiList) {
- // api 请求列表
- this.apiList = apiList
- // axios 实例
- this.instance = axios.create({
- timeout: 10000, // 请求超时时间
- withCredentials: true, // 自动携带 cookie
- ...config
- });
-
- // 请求拦截
- this.instance.interceptors.request.use(
- (config) => {
- // const token = cookies.get("token") ?? "";
- config.headers.Authorization = token;
- return config;
- },
- (err) => Promise.reject(err)
- );
-
- // 响应拦截
- this.instance.interceptors.response.use(
- (res) => {
- const { data } = res;
- return Promise.resolve(d
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。