Img src through props.
Following the docs you can use a relative src for the image tag as the following, which then nuxt knows that it's a file that it should import in the build step, how can you add support for this kind of image importing in props?
2 Replies
Hi @psyCOSMO. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To support image importing through props in Nuxt 3, you need to use a different approach compared to the static
src
attribute. The ~/assets/
syntax is not automatically resolved when passed as a prop. Here's how you can handle this:
1. Import the image in the parent component:
2. In the child component, use the imported image as the src
:
Alternatively, you can use the useImage
composable provided by Nuxt Image module to handle dynamic image imports:
This approach allows you to pass the image path as a prop and still benefit from Nuxt's image optimization features.
For more information on using images in Nuxt 3, you can refer to the following resources:
Nuxt 3 Assets Documentation
Nuxt Image Usage Documentation
Remember to install and configure the Nuxt Image module if you haven't already:
This will enable advanced image handling capabilities in your Nuxt 3 project.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@257100970050191362> Kapa.ai is still learning and improving, please let me know how I did by reacting below.