zoukankan      html  css  js  c++  java
  • vue判断图片为空或者图片加载不成功时显示默认图片

    纯css解决方案:

    <img src="broken.png" alt="">
    img {
      position: relative;
    }
    
    img:after { 
      content: url('替代圖片');
      display: block;
      position: absolute;
      // 底下是故意要填满并且背景填滿擋住底下那個很醜的加載失敗圖片(字体)
      z-index: 2;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: #fff;
    }

    这样使用是应为img标签的一些特性:

    1,img是个比较特殊的标签,和video一样具有被替代性,所有当图片加载成功时,原先定义的伪类会失去作用不提示。

    2,alt属性会在图片加载失败是出现(替代文字),这样伪类就会起作用了。

    网上很多说这样也可以解决,但我测试暂未成功:

    <div class="bg">
         <img :src="goods.phoneFloorAd.resUrl" :onerror="errorImg01">
    </div>
    <script type="text/ecmascript-6">
    export default {
            data () {
                return {
                  errorImg01: 'this.src="' + require('assets/images/load_logo01.png') + '"'
            };
        }
    }
    </script>
  • 相关阅读:
    Activity生命周期回顾
    Android Camera拍照 压缩
    Android获取相册图片
    Android 常用系统控件
    Java synchronized详解
    Android输入法开发
    Android Toast和Notification
    Extjs 自定义控件
    在Extjs中动态增加控件
    数据库中存储js代码无法json解析
  • 原文地址:https://www.cnblogs.com/Han39/p/9359589.html
Copyright © 2011-2022 走看看