码迷,mamicode.com
首页 > 其他好文 > 详细

vue 图片404问题

时间:2020-05-25 19:43:28      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:remove   style   element   com   cron   阳光   default   this   def   

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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

vue 图片404问题

标签:remove   style   element   com   cron   阳光   default   this   def   

原文地址:https://www.cnblogs.com/qq364735538/p/12960282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!