当前位置:网站首页>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);
}
);
改成这种后就不再报错了
边栏推荐
- Roll up, break through 35 year old anxiety, and animate the CPU to record the function call process
- Flutter development: use safearea
- Wechat applet - simple diet recommendation (3)
- oracle和mysql批量Merge对比
- RMS TO EAP通过MQTT简单实现
- 写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
- Kotlin compose multiple item scrolling
- Optimize database queries using the cursor object of SQLite
- Kotlin compose and native nesting
- Mobile heterogeneous computing technology GPU OpenCL programming (Advanced)
猜你喜欢
Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
卷起来,突破35岁焦虑,动画演示CPU记录函数调用过程
宝塔面板MySQL无法启动
Kotlin Compose 多个条目滚动
Hard core, have you ever seen robots play "escape from the secret room"? (code attached)
. Net delay queue
盗版DALL·E成梗图之王?日产5万张图像,挤爆抱抱脸服务器,OpenAI勒令改名
From "chemist" to developer, from Oracle to tdengine, two important choices in my life
解决idea调试过程中liquibase – Waiting for changelog lock….导致数据库死锁问题
On July 2, I invite you to TD Hero online press conference
随机推荐
高级 OpenCV:BGR 像素强度图
Design and exploration of Baidu comment Center
7 月 2 日邀你来TD Hero 线上发布会
Application of data modeling based on wide table
Data visualization platform based on template configuration
如何获取GC(垃圾回收器)的STW(暂停)时间?
The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?
百度智能小程序巡检调度方案演进之路
能源势动:电力行业的碳中和该如何实现?
La voie de l'évolution du système intelligent d'inspection et d'ordonnancement des petites procédures de Baidu
基于模板配置的数据可视化平台
Tdengine already supports the industrial Intel edge insight package
Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 -下
How to correctly evaluate video image quality
Generics, generic defects and application scenarios that 90% of people don't understand
Officially launched! Tdengine plug-in enters the official website of grafana
[200 opencv routines] 219 Add digital watermark (blind watermark)
硬核,你见过机器人玩“密室逃脱”吗?(附代码)
Apache DolphinScheduler 入门(一篇就够了)
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...