This commit is contained in:
王子琦
2026-01-14 15:11:25 +08:00
parent cd5a2a3255
commit f006ed4c89
73 changed files with 4632 additions and 0 deletions

28
frontend/src/api/http.js Normal file
View File

@@ -0,0 +1,28 @@
import axios from 'axios'
import { useAuthStore } from '../store/auth'
const http = axios.create({
baseURL: 'http://localhost:8080',
timeout: 15000
})
http.interceptors.request.use((config) => {
const store = useAuthStore()
if (store.token) {
config.headers.Authorization = `Bearer ${store.token}`
}
return config
})
http.interceptors.response.use(
(response) => {
const res = response.data
if (res.code !== 0) {
return Promise.reject(new Error(res.message || '请求失败'))
}
return res.data
},
(error) => Promise.reject(error)
)
export default http