当前位置:网站首页>[error reporting] "typeerror: cannot read properties of undefined (reading 'split')“

[error reporting] "typeerror: cannot read properties of undefined (reading 'split')“

2022-07-05 00:09:00 Blog Zhu hukang

Report the wrong question

In the use of split() Method is divided into strings , The red information is as follows :Cannot read properties of undefined (reading ‘split‘)

Error reporting analysis

Before dividing the data , First judge whether the current data is empty ; If you don't judge the data , Can cause an exception . So in calling splid() Function before , You need to make a non empty judgment on the data that currently needs to be segmented ( Or call when the data is not empty ).

Error reporting solution

Before dividing the data , First judge whether the current data is empty ; If you don't judge the data , Can cause an exception . So in calling splid() Function before , You need to make a non empty judgment on the data that currently needs to be segmented ( Or call when the data is not empty ).

const imgUrl = "https://tu.cloud.cn/flower/flower-size.jpg?size=1800";
//  When the data is not empty 
if(imgUrl) {
    
  //  Intercept   Then splice the new string 
  const newImgUrl = imgUrl.split('?')[0] + "?size=600";
  console.log(newImgUrl);  //https://tu.cloud.cn/flower/flower-size.jpg?size=600
}
原网站

版权声明
本文为[Blog Zhu hukang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050005308783.html