dl_site_nuxt/plugins/axios.js
2025-10-09 20:45:30 +08:00

41 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default function ({redirect, $axios, app}) {
// 数据访问前缀
$axios.defaults.baseURL = process.env.NUXT_ENV.VUE_APP_API_URL;
// 请求拦截器
$axios.interceptors.request.use(
config => {
config.params = {
...config.params,
tenantId: 'main',
showPlat:"网站"
}
if (config.method === 'post') {
config.data = {
...config.data,
tenantId: 'main'
}
}
return config
},
error => {
return Promise.reject(error)
}
)
// response拦截器数据返回后可以先在这里进行一个简单的判断
$axios.interceptors.response.use(
response => {
let code = response.data ? response.data.code : 500;
switch (code) {
case 200:
return response.data
default:
return Promise.reject(response.data.msg)
}
},
error => {
if(process.client){
}
return Promise.reject(error) // 返回接口返回的错误信息
})
}