You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
635 B

9 months ago
// 引入第三方请求库axios
import axios from 'axios'
import pinia from '@/store'
import userStore from '@/store/module/user'
9 months ago
// 创建axios实例
const server = axios.create({
8 months ago
baseURL: import.meta.env.VITE_APP_BASE_API,
timeout: 30000,
9 months ago
})
// 创建请求拦截器
8 months ago
9 months ago
server.interceptors.request.use((config) => {
8 months ago
const useuserStore = userStore(pinia)
8 months ago
config.headers.Authorization = useuserStore.token
config.headers['x-access-token'] = useuserStore.token
return config
9 months ago
})
// 创建相应拦截器
server.interceptors.response.use((response) => {
8 months ago
return response.data
9 months ago
})
// 暴露axios实例
8 months ago
export default server