Answer the question
In order to leave comments, you need to log in
How to handle v-img error?
Hello!
How can I catch the 404 error (if there is no image), instead show the image that the image is not loaded?
v-for="(product, index) in currentPageItems"
:key="index"
>
<div class="px-2 pt-2">
<v-img v-if = "image === true"
:src="$hostname + `/uploads/images/goods/${product.imageSrc}`"
height="200px"
contain
position='center'
v-on:error="onImgError"
/>
<v-img v-else
class="mt-3 grey light-2"
:src="$hostname + `/uploads/images/nopic.png`"
height="200px"
contain
position='center'
/>
</div>
Answer the question
In order to leave comments, you need to log in
Add a Boolean property to currentPageItems to indicate if there is an error. Assign src depending on the value of this property. Set it to true when handling the error event.
https://jsfiddle.net/vuz756br/
v-if = "product.imageSrc"
or
class="mt-3 gray light-2"
:src="product.imageSrc ? `${hostname} + /uploads/images/goods/${product.imageSrc}` : `${hostname} + /uploads/images/nopic.png`"
height="200px"
contain
position='center'
/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question