I'm trying to render four images using v-for with a range, 1 to 4.
v-for="n in 4" :key"n"
But, using 'n' as part of src does not work. Why?
<div v-for="n in 4" :key="n">
<img
:src="`../assets/images/image-product-${n}-thumbnail.jpg`"
class="rounded-xl h-16 w-16 hover:cursor-pointer"
/>
</div>
Tried using 'key' instead of 'n', converting 'n' to string... none worked
If I hardcorde like this, it works
<img
src="../assets/images/image-product-1-thumbnail.jpg"
class="rounded-xl h-16 w-16 hover:cursor-pointer"
/>
If you have a global aliases (@) available i recommend you to use it.
Because using relative path can works in local for example but when the project is compile (build) the related path can be broken.
When using dynamic src path you can require it before loading.
With the aliases you can do: