当前位置:网站首页>TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
2022-07-05 09:41:00 【Oliver尹】
问题:在封装axios的时候,测试阶段突然报错TypeError: Cannot read properties of undefined (reading ‘cancelToken’)
描述:最近,为了解决老的axios封装中存在的一些问题,决定对axios的封装进行改动优化一下,当改完请求拦截之后进入自测的时候,突然报错TypeError: Cannot read properties of undefined (reading ‘cancelToken’),很奇怪,因为还没有到cancelToken这一部分
解答:其实原因很简单,请求拦截器编写完成之后,没有将config返回,那么就会报这个错,着实大意了
// 报错了
this.axios.interceptors.request.use(
(config: AxiosRequestConfig) => {
requestInterceptors(config);
},
(error) => {
Promise.reject(error);
}
);
这里的请求拦截器必须改成有返回值
this.axios.interceptors.request.use(
(config: AxiosRequestConfig) => {
return requestInterceptors(config);
},
(error) => {
Promise.reject(error);
}
);
改成这种后就不再报错了
边栏推荐
- mysql80服务不启动
- 90%的人都不懂的泛型,泛型的缺陷和应用场景
- 分布式数据库下子查询和 Join 等复杂 SQL 如何实现?
- The essence of persuasion is to remove obstacles
- Android SQLite database encryption
- E-commerce apps are becoming more and more popular. What are the advantages of being an app?
- About getfragmentmanager () and getchildfragmentmanager ()
- Fluent development: setting method of left and right alignment of child controls in row
- 【C语言】动态内存开辟的使用『malloc』
- What are the advantages of the live teaching system to improve learning quickly?
猜你喜欢
美图炒币半年亏了3个亿,华为被曝在俄罗斯扩招,AlphaGo的同类又刷爆一种棋,今日更多大新闻在此...
The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
The writing speed is increased by dozens of times, and the application of tdengine in tostar intelligent factory solution
Cent7 Oracle database installation error
如何正确的评测视频画质
Apache DolphinScheduler 系统架构设计
Develop and implement movie recommendation applet based on wechat cloud
基于单片机步进电机控制器设计(正转反转指示灯挡位)
卷起來,突破35歲焦慮,動畫演示CPU記錄函數調用過程
Uncover the practice of Baidu intelligent testing in the field of automatic test execution
随机推荐
如何正确的评测视频画质
What should we pay attention to when developing B2C websites?
从“化学家”到开发者,从甲骨文到 TDengine,我人生的两次重要抉择
Coffeescript Chinese character to pinyin code
分布式数据库下子查询和 Join 等复杂 SQL 如何实现?
卷起来,突破35岁焦虑,动画演示CPU记录函数调用过程
Flutter development: a way to solve the problem of blank space on the top of listview
单片机原理与接口技术(ESP8266/ESP32)机器人类草稿
Oracle combines multiple rows of data into one row of data
MySQL character type learning notes
E-commerce apps are becoming more and more popular. What are the advantages of being an app?
Hard core, have you ever seen robots play "escape from the secret room"? (code attached)
Android SQLite database encryption
【系统设计】指标监控和告警系统
oracle和mysql批量Merge对比
Common fault analysis and Countermeasures of using MySQL in go language
. Net delay queue
善用兵者,藏于无形,90 分钟深度讲解最佳推广价值作品
TDengine可通过数据同步工具 DataX读写
卷起來,突破35歲焦慮,動畫演示CPU記錄函數調用過程