vue项目中图片加载不到时,使用默认图片替换
解决方法:
①使用三目运算符
②使用onerror
<img
:src="item.photo ? item.photo :''"
alt="头像"
class="photo"
:onerror="defaultImg"
/>
computed: {
defaultImg(){
return 'this.src="'+ require('@/assets/img/photo.png') +'"'
}
},