vue图片加载与显示默认图片实例代码
更新时间:2017年03月16日 11:10:18 作者:Redchar
这篇文章主要为大家详细介绍了vue图片加载与显示默认图片的实例代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了vue图片加载与显示默认图片的具体代码,供大家参考,具体内容如下
HTML:
<div class="content-show-img"> <div class="show-img"> <img class="default-image" :src="data.image" @load="successLoadImg" @error="errorLoadImg"> </div> </div>
JS:
Vue.prototype.successLoadImg = function(event) {
if (event.target.complete == true) {
event.target.classList.remove("default-image");;
var imgParentNode = event.target.parentNode;
if(imgParentNode.classList.contains('show-img')==true){
imgParentNode.style.background = "#000";
}
}
};
Vue.prototype.errorLoadImg = function(event) {
event.target.classList.add("default-image");;
};
针对尺寸不统一的:先显示默认图片,加载成功时移除默认图片,填充背景。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
vue-resource 拦截器interceptors使用详解
这篇文章主要介绍了vue-resource 拦截器interceptors使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-01-01


最新评论