首页 > 解决方案 > 将图像作为道具传递的最佳方式?

问题描述

我正在尝试将图像作为道具从父组件传递给子组件,如下所示:

家长:

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} />

但是图像没有渲染,知道有什么问题吗?

标签: reactjsimagereact-props

解决方案


解决方案:

子组件:

<Image src={content.image.default} alt={content.title} />

推荐阅读