img标签,当src的url404时

1、使用默认图片代替

<img style="margin-left: 40px;width: 130px;height: 130px;" :src="url" @error="nofindImg()"/>

    nofindImg(){

      let img = event.srcElement;

      img.src = "../../../static/404.png";

      img.onerror = null; //防止一直跳动

    },

2、not found,直接删除标签

<img style="margin-left: 40px;width: 130px;height: 130px;" :src="url"  :οnerrοr="default"/>

data中定义默认图地址

  data() {

    return {

       default: 'this.remove()'

    };



作者:踩着阳光
链接:https://www.jianshu.com/p/c83ed05c57a1
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-05-11
  • 2021-12-24
  • 2022-01-26
  • 2021-05-23
猜你喜欢
  • 2022-01-10
  • 2021-11-20
  • 2021-11-07
  • 2021-08-26
  • 2021-04-27
  • 2022-12-23
相关资源
相似解决方案