Spaces:
Sleeping
Sleeping
File size: 658 Bytes
f8e5603 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import axios from 'axios'
const apiBase = import.meta.env.VITE_API_BASE || '/api'
const api = axios.create({
baseURL: apiBase,
headers: {
'Content-Type': 'application/json',
},
})
export const request = async (path, options = {}) => {
try {
const response = await api({
url: path,
...options,
})
const payload = response.data || {}
if (payload.code !== 0) {
throw new Error(payload.msg || '请求失败')
}
return payload.data
} catch (error) {
if (error.response?.data) {
const payload = error.response.data
throw new Error(payload.msg || error.message)
}
throw error
}
}
|