1👍
I can’t explain the console.logs at the bottom of your question, but based on the child component code I believe there are two changes needed to fix the overall issue.
require
shouldn’t ever be used in code when using Vite sincerequire
is ESM only. The Vite documentation describes a better way to import dynamic assets usingnew URL
withimport.meta.url
. One caveat is that you can’t use@
alias when constructing the URL due to Rollup limitations (Vite’s bundler). YourimgSrc
then should look like this:
const imgSrc = computed(
() => new URL(`../assets/images/subject/${subject.value.image}`, import.meta.url).href
);
(actual relative path might be different on your local machine)
- Change from using
reactive
totoRef
when creatingsubject
. Sinceprops
is reactive and you want to pull out the individual (non-reactive) property, you would use toRef for the job specifically because it keepssubject
andprops.subject
synced together.
const subject = toRef(props, 'subject');
I don’t have your exact same setup but when I tested it locally with some mock data/local image files instead of an API it worked for me. If you still have problems let me know.
Source:stackexchange.com