- 先看问题 类型“AxiosResponse<any, any>”上不存在属性“errorinfo”。ts(2339)
- 接口是返回有这个字段的,但是依然飘红,尝试了好多方法不行。
解决方法: 请求封装文件里面加
import axios, { Axios, AxiosResponse, AxiosRequestConfig } from "axios";
// 处理 类型“AxiosResponse<any, any>”上不存在属性“errorinfo”。ts(2339) 脑壳疼!关键一步。
declare module "axios" {
interface AxiosResponse<T = any> {
errorinfo: null;
// 这里追加你的参数
}
export function create(config?: AxiosRequestConfig): AxiosInstance;
}
const service = axios.create({
baseURL:BasURL, // 强哥
// baseURL:import.meta.env.MODE === "production" ? apis.production:apis.development ,
timeout:60000, // 请求毫秒
withCredentials:true, // 异步请求携带cookie
headers:{
// 设置后端需要的传参类型
'Content-Type': 'application/json;charset=UTF-8;',
'token': 'your token',
'X-Requested-With': 'XMLHttpRequest',
}
})
嘿嘿,解决了,
注意: 保存后可能不会立即生效,需要把当前文件关闭,再打开,就OK了。
标签:
前端
本文转载自: https://blog.csdn.net/qq_42957741/article/details/127245980
版权归原作者 邱志刚 所有, 如有侵权,请联系我们删除。
版权归原作者 邱志刚 所有, 如有侵权,请联系我们删除。