这是我的 axios 配置:
const axiosApi = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL
})
axiosApi.interceptors.response.use(
response =>
response
,
error => {
if (error.response.status === 404) {
throw new Error(`404\nService does not exist\n${error.request.path}`)
}
}
)
export async function get(url) {
console.log(url)
return await
axiosApi.get(url, {
crossDomain: true
}).then(response => {
return response?.data
})
}
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试 get 时/path?key=value,我收到/pathkey=value does not exist错误。
虽然console.log(url)向我显示带有问号和查询字符串的真实 URL,但响应拦截器会删除问号并导致 404。
知道为什么会发生这种情况吗?
您应该传递如下查询参数:
axios.get('/path', { params: { key: value} });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
982 次 |
| 最近记录: |