bug
This commit is contained in:
@@ -2,16 +2,20 @@ import axios from 'axios'
|
||||
import i18n from '../i18n/i18n'
|
||||
import store from '../vuex/store'
|
||||
|
||||
const urlHost = store.getters.serverUrl
|
||||
|
||||
axios.defaults.timeout = 50000
|
||||
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
|
||||
// 补充GET请求默认Content-Type(可选,GET请求通常无需此配置,但部分后端可能需要)
|
||||
axios.defaults.headers.get['Content-Type'] = 'application/json;charset=UTF-8'
|
||||
|
||||
// 请求拦截器
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
const urlHost = store.getters.serverUrl
|
||||
if (urlHost && !config.url.startsWith('http')) {
|
||||
// 移除urlHost和sevmethod中的多余斜杠,确保只保留一个
|
||||
const base = urlHost.replace(/\/$/, '')
|
||||
const path = config.url.replace(/^\//, '')
|
||||
config.url = `${base}/${path}`
|
||||
}
|
||||
config.headers['Accept-Language'] = i18n.locale === 'en-us' ? 'en' : 'zh'
|
||||
return config
|
||||
},
|
||||
@@ -53,7 +57,7 @@ axios.interceptors.response.use(
|
||||
|
||||
export const post = (sevmethod, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(`${urlHost}/${sevmethod}`, params)
|
||||
axios.post(sevmethod, params)
|
||||
.then(response => {
|
||||
resolve(response.data)
|
||||
})
|
||||
@@ -65,7 +69,7 @@ export const post = (sevmethod, params) => {
|
||||
|
||||
export const get = (sevmethod, params = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.get(`${urlHost}/${sevmethod}`, { params })
|
||||
axios.get(sevmethod, { params })
|
||||
.then(response => {
|
||||
resolve(response.data)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user