Event on-error in is not working?

Event on-error in <img> is not working?



I using VueJS to code front-end and I have a problem with tag when loading image.


Template
<div class="items" transition="fade" v-for="item in list">
<img :src="item.logoPath" @error="replaceByDefault">
</div>

JS(ES6)
export default
methods:
replaceByDefault(e)
// code here to replace image by default



template: require('./template.html')



Currently, I had debug in replaceByDefault function but it's not run into this function? I don't know why?



Could you help me explain this problem? thanks!




3 Answers
3



I have encountered a similar problem, my solution is the following code snippet, I know this solution is certainly not the best, but if your situation is very urgent, such as me, you can use the following solutions, let us Together looking for a better solution to appear


<img onerror="javascript:this.src='error.png'">





While this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.
– Adam
Apr 11 '17 at 20:54





Sorry, last night I just wanted to solve the problem as soon as possible, I also know that this is not the best solution
– hedgehog
Apr 12 '17 at 14:41



I tried to do something similar to this but my problem was that I getting 404 on some of the images and I wanted to replace the image with a default image.



this is my solution:


<template>
<div :key="index" v-for="(item, index) in list">
<img :src="item.logo" @error="replaceByDefault">
</div>
</template>

<script>
import img from '<<URL>>'
export default
methods:
replaceByDefault(e)
e.target.src = img



</script>



Thank everybody read this my problem, I resolved this problem :).



The reason on-error event does not work is because the property 'logoPath' of item object does not exist, so, the ':src' in vueJS is not bind to and that src of image does exist => on-error does not work :)



My bad :(



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế