reactjs - 将 React 变量传递给“href”属性
问题描述
我尝试使用路径传递变量的值 to href
,我有问题让它工作:
export const TechnicalInformationPure = ( props: AllProps ) => {
const { t } = useTranslation();
const { component } = props;
let hrefLink = '/solution/components/' + component?.id + '/attachments/' + attachment.id;
console.log(component)
return (
<DetailsBox title={t('catalogPage.componentDetails.specs.technicalInfo')}>
<Typography variant="body1" component="p" gutterBottom>
{component?.attachments.technical_docs.map(attachment => (
<li style={{ listStyleType: 'none' }} key={1}>
<a target="_blank" rel="noopener noreferrer" href={attachment.toString()}>
{attachment.filename.toString() + attachment.format.toString()}
</a>
{<Link target="_blank" href="HerePath">Download</Link>}
</li>
))
}
</Typography>
</DetailsBox>
);
};
如何分配一个hrefLink
变量以使其在下面的行中:
{<Link target="_blank" href="HerePath">Download</Link>}
我确信我认为不好的事情,但不知道如何按我的意愿解决它。
解决方案
尝试这样分配hrefLink
:
<Link target="_blank" href={hrefLink}>Download</Link>
全<li>
元素:
<li style={{ listStyleType: 'none' }} key={1}>
<a target="_blank" rel="noopener noreferrer" href={attachment.toString()}>
{attachment.filename.toString() + attachment.format.toString()}
</a>
<Link target="_blank" href={hrefLink}>Download</Link>
</li>
推荐阅读
- javascript - mqtt JS文件中的多个SUB
- javascript - 编号我从 txt 文件加载的行
- javascript - 我无法调用分配给 React 中元素的函数
- c++ - 如何抑制从 CommCtrl.h 中提取的 C26454 代码分析?
- azure - 如何配置 Azure 应用程序网关以允许连接到容器实例
- c# - 部署后未出现静态 .gif
- php - 如何在优惠券规则 Magneto 2 上添加自定义选项值
- gitpod - 是否可以在 Gitpod 中取消删除文件?
- python - 如何对fasta文件的标题进行分组
- javascript - 如何使用 PHP 和 cURL 将 e.parameter 发送到 Google Apps 脚本