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