Nuxt-image not working with dynamic src
Nuxt-image does not work with dynamic src in target: static mode and if you specify genegate: {dir: nameDir} in nuxt.config.js. If we specify all this, then the path to the image is set incorrectly. What can be done in such a case? If I use the same thing in a regular tag, then everything works as it should
I do have the same issue using storyblok as the source of the images.
note: *nuxt2, @nuxt/image
acording to this code prerender.ts#L5C3-L5C50
if (!process.server || !process.env.prerender) { return }
image module only works when render image on server-side and enable prerender.
I got out of the problem the following way, I write <nuxt-img src="img/1.svg" /> and everything works, remove the first / and that's it
thanks for you feed back. i am using [email protected] with the @nuxt/[email protected]. i have made a trial, it does not work as expected
One can still use a variable to hold the path name and the image can be placed in the public directory. In my case images dir.
so:
nuxt-project/public/images
<template>
<NuxtImg :src="srcImage"/>
</template>
<script setup lang="ts">
const fourOFourImage = "/images/svg/404.svg";
const galleryNotAvailableImage = "/images/svg/gallery-not-available.svg";
const userNotFoundImage = "/images/svg/user-not-found.svg";
const srcImage = computed(() => {
// ... here some logic to choose from one of the variables above
});
</script>
Nuxt will automatically look for the images folder inside the public dir.