当前位置:网站首页>【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
2022-07-05 00:05:00 【博客zhu虎康】
报错问题
在使用 split()方法分割成字符串时,报红信息如下:Cannot read properties of undefined (reading ‘split‘)
报错分析
在对数据进行分割以前,要先判断当前数据是否存在为空的情况;如果不对数据进行判断,可能会导致异常。所以在调用 splid() 函数前,需要对当前需要进行分割的数据进行非空的判断(或者是当数据不为空的情况下调用)。
报错解决
在对数据进行分割以前,要先判断当前数据是否存在为空的情况;如果不对数据进行判断,可能会导致异常。所以在调用 splid() 函数前,需要对当前需要进行分割的数据进行非空的判断(或者是当数据不为空的情况下调用)。
const imgUrl = "https://tu.cloud.cn/flower/flower-size.jpg?size=1800";
// 当数据不为空的情况下
if(imgUrl) {
// 截取 再拼接新的字符串
const newImgUrl = imgUrl.split('?')[0] + "?size=600";
console.log(newImgUrl); //https://tu.cloud.cn/flower/flower-size.jpg?size=600
}
边栏推荐
- P4281 [AHOI2008]紧急集合 / 聚会(LCA)
- Netcore3.1 JSON web token Middleware
- C语言中sizeof操作符的坑
- Business implementation - the log is written to the same row of data
- Basic points of the game setup of the points mall
- Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
- Is it safe to open and register new bonds? Is there any risk? Is it reliable?
- IELTS examination process, what to pay attention to and how to review?
- Selected cutting-edge technical articles of Bi Ren Academy of science and technology
- Life is changeable, and the large intestine covers the small intestine. This time, I can really go home to see my daughter-in-law...
猜你喜欢
How to use fast parsing to make IOT cloud platform
Illustrated network: what is gateway load balancing protocol GLBP?
ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
[IELTS reading] Wang Xiwei reading P4 (matching1)
45岁教授,她投出2个超级独角兽
Blue sky nh55 series notebook memory reading and writing speed is extremely slow, solution process record
What is the difference between port mapping and port forwarding
同事的接口文档我每次看着就头大,毛病多多。。。
机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)
Pytoch --- use pytoch to realize linknet for semantic segmentation
随机推荐
It's too convenient. You can complete the code release and approval by nailing it!
快解析内网穿透帮助企业快速实现协同办公
Introduction to ACM combination counting
abc 258 G - Triangle(bitset)
Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
JS how to realize array to tree
Face recognition 5- insight face padding code practice notes
Instructions for go defer
"Xiaodeng" domain password policy enhancer in operation and maintenance
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
Meet ThreadPoolExecutor
认识ThreadPoolExecutor
Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
海思3559万能平台搭建:YUV422的踩坑记录
Verilog tutorial (11) initial block in Verilog
PaddleOCR教程
[JS] - [sort related] - Notes
P4408 [NOI2003] 逃学的小孩(树的直径)
多回路仪表在基站“转改直”方面的应用
45岁教授,她投出2个超级独角兽