当前位置:网站首页>【报错】 “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
}
边栏推荐
- ICML 2022 | 3dlinker: e (3) equal variation self encoder for molecular link design
- The input of uniapp is invalid except for numbers
- Hologres Query管理及超时处理
- Using the uniapp rich text editor
- Microservice
- 快解析内网穿透帮助企业快速实现协同办公
- Best practice case of enterprise digital transformation: introduction and reference of cloud based digital platform system security measures
- Intelligence test to see idioms guess ancient poems wechat applet source code
- 如果炒股开华泰证券的户,在网上开户安全吗?
- The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
猜你喜欢
45 year old professor, she threw two super unicorns
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
How long does it take to obtain a PMP certificate?
企业公司项目开发好一部分基础功能,重要的事保存到线上第一a
The input of uniapp is invalid except for numbers
业务场景功能的继续修改
微服务(Microservice)那点事儿
【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
French scholars: the explicability of counter attack under optimal transmission theory
取得PMP證書需要多長時間?
随机推荐
The input of uniapp is invalid except for numbers
[IELTS reading] Wang Xiwei reading P3 (heading)
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
快解析——好用的内网安全软件
Netcore3.1 JSON web token Middleware
Design of emergency lighting evacuation indication system for urban rail transit station
Parsing of XML
Using the uniapp rich text editor
OpenHarmony资源管理详解
他做国外LEAD,用了一年时间,把所有房贷都还清了
人脸识别5- insight-face-paddle-代码实战笔记
Jar批量管理小工具
Fast analysis -- easy to use intranet security software
[monitoring] ZABBIX
【北京大学】Tensorflow2.0-1-开篇
abc 258 G - Triangle(bitset)
In June, the list of winners of "Moli original author program" was announced! Invite you to talk about the domestic database
Application of fire fighting system based on 3D GIS platform
P3304 [SDOI2013]直径(树的直径)
Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC