vue中img图⽚加载中以及加载失败显⽰默认图⽚问题
加载中默认图⽚:
主要是onload事件监听,data中定义变量
imgSrc :require('./default.png');
<div class="per-pic" v-for="(item, index) in picData" :key="index">
英文生日祝福语
<img :src="imgSrc" :onload="loadImg(item.url)" />
圣诞节祝福
</div>
/*
**图⽚加载中
* */梦见乌龟是什么意思
loadImg($img){
return 'this.οnlοad=null;this.src='+'"'+$img+'";';
},
加载失败⽬前⽹上很多都是⽤onerror事件监听,然后给this.src赋值,压根不管⽤啊,试了半天不管⽤。
⽤css倒是能轻松解决,具体代码如下:
img{
width: 145px;
height: 145px;
position: relative;
高考选专业&:after{
content: "";
display: inline-block;
position: absolute;
z-index: 2;
top: 0;
left: 0;
width: 100%;
height: 145px;
background: url("./default.png") no-repeat;
银行贷款基准利率background-size: 100% ;
background-color: #fff;
}
};
考研数学怎么复习
觉得好⽤的,请点赞,蟹蟹。