vue图片加载与显示默认图片实例代码

作者:简简单单 2017-07-03

HTML:

 

 代码如下 复制代码

  

    

  

 

JS:

 

 代码如下 复制代码

Vue.prototype.successLoadImg =function(event) {

  if(event.target.complete ==true) {

    event.target.classList.remove("default-image");;

    varimgParentNode = 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");;

};

 

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

相关文章

精彩推荐