当前位置:网站首页>微信小程序图片无法显示时显示默认图片
微信小程序图片无法显示时显示默认图片
2022-07-26 09:25:00 【44w0】
最近开发的项目是微信小程序,动态显示图片,遇到了一些问题
- 图片是从别的网站获取的网络图片,使用image标签无法正常显示
解决方案: 使用原生img标签,添加属性referrerPolicy=“no-referrer”
<img referrerPolicy="no-referrer" :src="item.picPath" >
此时图片可以显示出来了
2.之后发现有几个图片一直加载失败,就让其显示自己设置的默认图片(微信小程序不管用)
解决方案:处理图片加载失败的问题,使用onerror事件捕捉图片加载错误,使用默认图片
<img referrerPolicy="no-referrer" :src="item.picPath" onerror="οnerrοr=null;src='../../static/exam/b1.png'" ></img>
注意: οnerrοr=null一定不能省略,否则不能实现效果
3.用h5测试onerror事件捕捉图片加载错误是正常的,但是如果使用微信小程序就会报错,我又去百度了一番
解决方案:微信小程序中img标签不支持onerror事件,使用@error方法
<img referrerPolicy="no-referrer" :src="item.picPath" @error="imageError($event, index)" ></img>
js部分:
imageError(e, index) {
this.newFinal[index].picPath = '../../static/exam/b1.png';
},
注意:在imageError方法中将无法显示的图片替换成本地静态图片时,注意应该直接对遍历的对象修改,如果传值item修改item,是无法显示默认图片的
边栏推荐
- asp.net 使用redis缓存(二)
- 大二上第一周学习笔记
- 微信小程序开发
- 服务器内存故障预测居然可以这样做!
- Windows通过命令备份数据库到本地
- Under a directory of ext3 file system, subfolders cannot be created, but files can be created
- Solve "note: one or more layouts are missing the layout_width or layout_height attributes."
- arc-gis基础操作3
- arcgis的基本使用1
- Exception handling mechanism II
猜你喜欢
随机推荐
What are CSDN spaces represented by
Local cache
CF1481C Fence Painting
登录模块用例编写
Ext4 file system opens dir_ After nlink feature, link_ Use link after count exceeds 65000_ Count=1 means the quantity is unknown
调用DLL开启线程的问题
Qt | 关于如何使用事件过滤器 eventFilter
docker配置mysql集群
What is asynchronous operation
TabbarController的封装
[shutter -- layout] detailed explanation of the use of align, center and padding
Paper notes: knowledge map kgat (unfinished temporary storage)
arc-gis的基本使用2
[MySQL] detailed explanation of MySQL lock (III)
nodejs服务后台执行(forever)
【Mysql】Mysql锁详解(三)
arcgis的基本使用1
JS output diamond on the console
ZXing简化版,转载
神经网络与深度学习-6- 支持向量机1 -PyTorch








