在<img>不起作用
Event on-error in <img> is not working?
我使用VueJS编写前端代码,在加载图像时我有一个标签问题。
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')
}
目前,我在replaceByDefault函数中调试,但它没有运行到这个函数中?我不知道为什么?
你能帮我解释一下这个问题吗?谢谢!
我试图做类似的事情,但我的问题是,我得到404上的一些图像,我想用默认的图像代替图像。
这是我的解决方案:
<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>
我也遇到过类似的问题,我的解决方案是下面的代码片段,我知道这个解决方案肯定不是最好的,但是如果你的情况很紧急,比如我,你可以使用下面的解决方案,让我们一起寻找一个更好的解决方案出现
<img onerror="javascript:this.src='error.png'">
感谢大家阅读我的问题,我解决了这个问题:)。
on-error事件不工作的原因是{item}对象的属性'logoPath'不存在,因此,vueJS中的':src'没有绑定,并且图像的src确实存在=> on-error不工作:)
My bad:
我用了不同的方法来解决这个问题,但它对我不起作用。之后我导入了图像地址。
<template>
<div :key="index" v-for="(item, index) in list">
<img :src="item.imagelist" @error="errorImage">
</div>
</template>
<script setup>
import img from 'urlImage'
function errorImage(e) {
e.target.src = img
}
</script>
相关文章:
- jQuery dataTables基于类型的列筛选不起作用?Img alt过滤器/排序
- javascript:created img onclick不起作用
- 当在 img 标签中提到类时,Href 不起作用
- jQuery 按 ID 名称删除 img 标签不起作用
- onClick 事件 onJavaScript img 标记不起作用
- 当它在IE中具有兄弟姐妹img时,拖动不起作用
- AngularJS - img ng-src 到 base64 数据(不是 url)不起作用
- jquery toggleClass 在 img 元素上不起作用
- 使用 ATTR 在 iOS 5 上不起作用更改 IMG 源
- 带有 base64 img 附件的电子邮件编辑器不起作用
- IMG 点击在 quore 时不起作用
- Jquery button img 更改在 IE 和 Firefox 中不起作用
- 奇怪的 img src 路径,在本地主机上不起作用
- 带有javascript调用的img在ipad上不起作用
- 除非window.onload,否则jQuery img.attr不起作用
- 将点击附加到 img 元素不起作用
- 锚标签onclick-around img标签在iphoneiOs9中不起作用
- img的jQuery.attr(“src”)不起作用
- img src中的流星模板不起作用
- Img点击在firefox中不起作用