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");;
};

针对尺寸不统一的:先显示默认图片,加载成功时移除默认图片,填充背景。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM