Currently, I am tackling SSR projects using Nuxt and Quasar. However, I encountered an issue when trying to display a dynamic image in a child component as the image is not being shown.
The snippet of my code in question is as follows:
function getUrl (img: string) {
return require(`@/assets/imgs/sidebar/${img}.png`);
}
An error message pops up stating:
Cannot find module '@/assets/imgs/sidebar/side_1.png.png' Require stack: - E:\Work\0503_game777\nuxt-quasar\components\sidebar\SideBarItem.vue
I have double-checked the image path, and it seems correct since the image displays when accessed directly.
I also attempted the following fix:
function getUrl (img: string) {
return `/_nuxt/assets/imgs/sidebar/${img}`;
}
This approach works fine locally; however, post-build, the image fails to load. Additionally, I tried importing the dynamic image path instead of using require(), resulting in a promise error. My current implementation is in TypeScript.