I am trying to render an image src path dynamically based on the prop provided to the component, and provide a fallback path if that image doesn't exist in the assets folder. Here is my image tag:
<img
:src="require(`@/assets/${project.image || 'day-1.jpg'}`)"
alt="project image"
class="rounded-xl row-span-3 col-span-1"
>
For the first instance of this component on the site, {project.image}
should (and does) provide the proper image file name from the store: gfs.jpg
(an image that does not exist in the file tree)
In this case, shouldn't my code above tell Webpack to render the day-1.jpg
image, due to the ||
or operator being used, since the file at gfs.jpg
is not found?
Webpack is throwing the error Cannot find module './gfs.jpg'
with error code 500
I also tried using an @error
tag that calls a handler function from methods: {}
, but that doesn't fire when this error occurs.