当前位置:网站首页>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);
}
);
改成这种后就不再报错了
边栏推荐
- 【C语言】动态内存开辟的使用『malloc』
- 一种用于干式脑电图的高密度256通道电极帽
- Mysql80 service does not start
- Uncover the practice of Baidu intelligent testing in the field of automatic test execution
- The comparison of every() and some() in JS uses a power storage plan
- Tianlong Babu TLBB series - questions about skill cooling and the number of attack ranges
- Roll up, break through 35 year old anxiety, and animate the CPU to record the function call process
- ArcGIS Pro 创建要素
- oracle和mysql批量Merge对比
- Tdengine already supports the industrial Intel edge insight package
猜你喜欢
Hard core, have you ever seen robots play "escape from the secret room"? (code attached)
Data visualization platform based on template configuration
Kotlin Compose 多个条目滚动
(1) Complete the new construction of station in Niagara vykon N4 supervisor 4.8 software
E-commerce apps are becoming more and more popular. What are the advantages of being an app?
TDengine可通过数据同步工具 DataX读写
La voie de l'évolution du système intelligent d'inspection et d'ordonnancement des petites procédures de Baidu
卷起来,突破35岁焦虑,动画演示CPU记录函数调用过程
Kotlin compose and native nesting
Apache DolphinScheduler 入门(一篇就够了)
随机推荐
Wechat applet - simple diet recommendation (3)
What should we pay attention to when developing B2C websites?
7 月 2 日邀你来TD Hero 线上发布会
基于单片机步进电机控制器设计(正转反转指示灯挡位)
Understand the window query function of tdengine in one article
【OpenCV 例程200篇】219. 添加数字水印(盲水印)
写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
How do enterprises choose the appropriate three-level distribution system?
MySQL数字类型学习笔记
View Slide
Jupiter notebook shortcut key
cent7安装Oracle数据库报错
Common fault analysis and Countermeasures of using MySQL in go language
mysql80服务不启动
[technical live broadcast] how to rewrite tdengine code from 0 to 1 with vscode
单片机原理与接口技术(ESP8266/ESP32)机器人类草稿
高级 OpenCV:BGR 像素强度图
Theme. AppCompat. Light. Darkactionbar not found
Apache dolphin scheduler system architecture design
How to get the STW (pause) time of GC (garbage collector)?