首页 > 解决方案 > 无法读取未定义的属性“替换”

问题描述

在此处输入图像描述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);

标签: javascriptreactjs

解决方案


听起来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);

推荐阅读