当前位置:网站首页>微信小程序图片无法显示时显示默认图片
微信小程序图片无法显示时显示默认图片
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,是无法显示默认图片的
边栏推荐
- 【Mysql】认识Mysql重要架构(一)
- 使用openLayer画箭头
- nodejs中mysql的使用
- [online problem] timeout waiting for connection from pool problem troubleshooting
- 大二上第一周学习笔记
- arc-gis的基本使用2
- Voice chat app source code - Nath live broadcast system source code
- Android implements the caching mechanism and caches multiple data types
- 2022 chemical automation control instrument operation certificate test question simulation test platform operation
- PHP一次请求生命周期
猜你喜欢
随机推荐
a-table中的rowSelection清空问题
"Could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32"
TableviewCell高度自适应
【线上死锁分析】由index_merge引发的死锁事件
Mysql事务
解决“NOTE: One or more layouts are missing the layout_width or layout_height attributes.”
Li Mu D2L (VI) -- model selection
点击input时,不显示边框!
Under a directory of ext3 file system, subfolders cannot be created, but files can be created
arcgis的基本使用4
您的登录IP不在管理员配置的登录掩码范围内
性格测试系统v1.0
Li Mu D2L (V) -- multilayer perceptron
语音聊天app源码——钠斯直播系统源码
asp.net 使用redis缓存(二)
模板(三)
MySql5.7.25源码安装记录
What is asynchronous operation
登录模块用例编写
Go intelligent robot alpha dog, alpha dog robot go



![[MySQL] detailed explanation of redo log, undo log and binlog (4)](/img/67/6e646040c1b941c270b3efff74e94d.png)





