javascript - 无法读取未定义的属性“替换”
问题描述
enter code here
我正在创建一个在线目录,每次单击“更多信息”按钮时,我都会得到一个无法读取replace
的属性undefined
我试图重命名,property
但它仍然无法正常工作
let removeCom = this.props.itemInfo.description.replace("?", "").replace('<td width="110" height="">', "").replace("http://extranet.acetools.com/Catalog/","assets/img/items/").replace((/<INPUT[^>]*>/gmi), "").split('<CENTER><FONT COLOR="RED">', 1);
console.log(removeCom);
解决方案
听起来description
是未定义的。您可能需要检查以确保 prop 正确传递给组件。
您还可以尝试将描述设置为默认值,这样就不会出现“无法读取未定义的属性'替换'”错误。
const { itemInfo: { description = '' } = this.props;
let removeCom = description.replace("?", "").replace('<td width="110" height="">', "").replace("http://extranet.acetools.com/Catalog/","assets/img/items/").replace((/<INPUT[^>]*>/gmi), "").split('<CENTER><FONT COLOR="RED">', 1);
推荐阅读
- php - Joomla:将文章图片放在 Facebook 的头部
- python - ValueError:无法在位置 0 解析字符串“不存在”
- lua - init.lua:389: 未找到模块“hdf5”:未找到 hdf5 的 LuaRocks 模块
- ios - 在 Firebase 数据库中的 MKMapView 上放置多个标记
- c# - 无法启动服务挂载被拒绝 '/usr/local/share/dotnet/sdk/NuGetFallbackFolder\r\n' 不是来自 macOS X 的共享并且 docker 不知道
- input - 如何阻止在输入标签上输入“qq.com”?
- python - Codechef 上的错误答案
- c# - 如何在应用程序内关闭时重新启动应用程序
- google-sheets - 如何使用列作为标识符
- python - pycharm可以通过ssh连接wsl但不能在wsl中使用python