#How to use SVG files with Nuxt.JS?
38 messages · Page 1 of 1 (latest)
you may be able to straight import them
i cant remember if vite handles SVGS like that or you need a plugin
https://nuxt.com/modules/nuxt-svgo is an option
Thanks again!
Straight import?
i meant like a vanilla import statement where there would be some behind the scenes magic to handle things for you
i;ve had projects where i can do import mysvg from '@/assets/this.svg' and it worked i just couldnt remember how
<img v-for="badge in badges" :src="require(`~/assets/svg/badges/${badge}.svg`)" :key="badge"/>
This is what I'm trying to do.
I've installed nuxt-svgo and everything but I still can't get it to work :/
Any help?
Hm
i havent done something like this before but i can give it a whirl
if your project is public maybe i can give it a run and try and figure that out for you
but i cant imagine require is going to be used
<template>
<img src="~/assets/img/nuxt.png" alt="Discover Nuxt 3" />
</template>
thats the base example from the docs so we would probably change that to be
<img :src="`~/assets/svg/badges/${badge}.svg`">
docs are here https://nuxt.com/docs/getting-started/assets
they specifically show that this works with SVGs
Nope, doesn't work
It just evaluates into ~/assets/svg/badges/nitro.svg in devtools
ok im trying to recreate a minimal example just give me a sec
looks like you found a bug potentially
i have a solution but its unfortunate
Absolute paths?
create vue components with just svgs in them in the template
no script needed
then use <component :is=""/> and inside the is you put the name of the component you created
Alright. That works.
Thanks!