Hi, I'm having trouble importing inline svgs into my nuxt3 vite project. Any advice would be greatly appreciated.
I found this works but I need an inline item. So I would do something like
setup(props) { const currentIcon = computed(() => { return defineAsyncComponent(() => import(`~/assets/images/icons/push-icon-chatops.svg'?inline`) ); }).value; return { currentIcon, }; },
But I found that the way vite is imported is strange, the result is either the url string displayed in v-html, or an unreadable object
I'm trying to use this plugin but without success.
https://github.com/nuxt-community/svg-module
For the TS Nuxt 3 project, the situation is as follows.
nuxt.config.ts
File:Component example:
Note that the last
?component
is very important, otherwise TS will report an error.Plug-in documentation: vite-svg-loader
It appears that vite is actually incompatible with the
@nuxtjs/svg
plugin. So the answer is to install a vite specific plugin, in this case I installed the vite plugin and then did this