reactjs - 将图像作为道具传递的最佳方式?
问题描述
我正在尝试将图像作为道具从父组件传递给子组件,如下所示:
家长:
const StarterContent = {
image: require('../../assets/images/bike.png'),
title: 'Starter',
price: '$149/mo',
description:
'Get to know Onfleet. Track, dispatch, manage, and analyze your fleet.',
buttonText: 'Start Free Trial',
};
...
<PricingCard content={StarterContent} />
子组件:
<Image src={content.image} alt={content.title} />
但是图像没有渲染,知道有什么问题吗?
解决方案
解决方案:
子组件:
<Image src={content.image.default} alt={content.title} />
推荐阅读
- c# - Outlook:启动后检测“发送/接收”何时完成
- aws-dms - AWS DMS 任务不会删除
- reactjs - react-i18next 循环结构转 JSON
- c++ - 用 grep 执行 grep: *.*: No such file or directory 错误
- dns - 如果服务器 IP 发生变化,Geolocation Route 53 和 DNS 缓存会如何表现?
- python - 当我尝试在 repl.it 上导入 termcolor 时,它只是说包操作失败
- r - R RDCOMClient 在 Word Doc 中查找和替换
- parameters - 自定义配方中的自定义项目
- .htaccess - 重写一个复杂的链接 .htaccess
- python - 由于只读属性错误,无法设置 protobuf 字段