I am currently attempting to dynamically render an image source path based on the provided prop in the component. In case the image does not exist in the assets folder, I want to include a fallback path. Below is the code snippet for 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 initial instance of this component on the website, the {project.image}
correctly provides the image file name from the store as: gfs.jpg
. However, this particular image does not exist in the file tree.
In this scenario, shouldn't the code above prompt Webpack to render the day-1.jpg
image due to using the ||
operator when the gfs.jpg
file is not found?
An error is being thrown by Webpack stating Cannot find module './gfs.jpg'
with error code 500
I also attempted to use an @error
tag that triggers a handler function within methods: {}
, but it does not execute when encountering this particular error.