当前位置:网站首页>【报错】 “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
}
边栏推荐
- Enterprise application business scenarios, function addition and modification of C source code
- 【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
- Ap8022 switching power supply small household appliances ACDC chip offline switching power supply IC
- [JS] - [sort related] - Notes
- If you open an account of Huatai Securities by stock speculation, is it safe to open an account online?
- 【路径规划】RRT增加动力模型进行轨迹规划
- [论文阅读] CarveMix: A Simple Data Augmentation Method for Brain Lesion Segmentation
- Hologres Query管理及超时处理
- [monitoring] ZABBIX
- 用快解析内网穿透实现零成本自建网站
猜你喜欢

Netcore3.1 JSON web token Middleware

机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)

【雅思阅读】王希伟阅读P4(matching1)

【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)
![[JS] - [sort related] - Notes](/img/b7/af467c7a169b73c3c4936072aef8b9.png)
[JS] - [sort related] - Notes

In the enterprise, win10 turns on BitLocker to lock the disk, how to back up the system, how to recover when the system has problems, and how to recover quickly while taking into account system securi

快解析内网穿透帮助企业快速实现协同办公

The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!

Using the uniapp rich text editor

How many triangles are there in the golden K-line diagram?
随机推荐
Basic points of the game setup of the points mall
[IELTS reading] Wang Xiwei reading P3 (heading)
Using fast parsing intranet penetration to realize zero cost self built website
uniapp 除了数字,其他输入无效
Paddleocr tutorial
French scholars: the explicability of counter attack under optimal transmission theory
Actual combat simulation │ JWT login authentication
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
电力运维云平台:开启电力系统“无人值班、少人值守”新模式
Consolidated expression C case simple variable operation
Parsing of XML
【监控】zabbix
How to effectively monitor the DC column head cabinet
[JS] - [sort related] - Notes
Business implementation - the log is written to the same row of data
Selected cutting-edge technical articles of Bi Ren Academy of science and technology
abc 258 G - Triangle(bitset)
Combien de temps faut - il pour obtenir un certificat PMP?
The input of uniapp is invalid except for numbers
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano