当前位置:网站首页>Show default image when wechat applet image cannot be displayed
Show default image when wechat applet image cannot be displayed
2022-07-26 09:46:00 【44w0】
The recently developed project is wechat applet , Dynamic display pictures , There are some problems
- Pictures are online pictures obtained from other websites , Use image Labels cannot be displayed normally
Solution : Use native img label , Add attribute referrerPolicy=“no-referrer”
<img referrerPolicy="no-referrer" :src="item.picPath" >
At this point, the picture can be displayed
2. After that, I found that several pictures failed to load , Just let it display the default picture set by itself ( Wechat applet doesn't work )
Solution : Handle the problem of image loading failure , Use onerror Event capture image loading error , Use default picture
<img referrerPolicy="no-referrer" :src="item.picPath" onerror="οnerrοr=null;src='../../static/exam/b1.png'" ></img>
Be careful : οnerrοr=null Must not omit , Otherwise, the effect cannot be achieved
3. use h5 test onerror It is normal that the event capture image is loaded incorrectly , But if you use wechat applet, you will report an error , I went to Baidu again
Solution : Wechat applet img Tags do not support onerror event , Use @error Method
<img referrerPolicy="no-referrer" :src="item.picPath" @error="imageError($event, index)" ></img>
js part :
imageError(e, index) {
this.newFinal[index].picPath = '../../static/exam/b1.png';
},
Be careful : stay imageError Method to replace a picture that cannot be displayed with a local static picture , Note that the traversal object should be modified directly , If passing value item modify item, The default picture cannot be displayed
边栏推荐
- 2021年山东省中职组“网络空间安全”B模块windows渗透(解析)
- POJ 1012 Joseph
- 学习笔记之常用数组api 改变原数组和不改变原数组的有哪些?
- 解决IE7 & IE8 存储cookie问题
- [fluorescent character effect]
- 2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
- 云原生(三十六) | Kubernetes篇之Harbor入门和安装
- Apple dominates, Samsung revives, and domestic mobile phones fail in the high-end market
- Modern medicine in the era of "Internet +"
- v-for动态设置img的src
猜你喜欢
Does volatile rely on the MESI protocol to solve the visibility problem? (top)
v-premission添加权限
Node memory overflow and V8 garbage collection mechanism
Interview shock 68: why does TCP need three handshakes?
Gauss elimination solves the inverse of matrix (Gauss)
Solve NPM -v sudden failure and no response
Drawing shadow error diagram with MATLAB
Development to testing: a six-year road to automation starting from 0
解决ProxyError: Conda cannot proceed due to an error in your proxy configuration.
2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
随机推荐
解决npm -v突然失效 无反应
Double authentication of server and client
matlab中的AR模型短时预测交通流
“互联网+”时代的现代医学
【信息系统项目管理师】初见高项系列精华汇总
Smart gourmet C language
The difference between thread join and object wait
Application of Gauss elimination
【Datawhale】【机器学习】糖尿病遗传风险检测挑战赛
Add DLL
新增市场竞争激烈,中国移动被迫推出限制性超低价5G套餐
配置ADCS后访问certsrv的问题
R language ggpubr package ggsummarystats function visualizes the grouping box diagram (custom grouping color) and adds the statistical values corresponding to the grouping under the x-axis label (samp
CSV data file settings of JMeter configuration components
Node 内存溢出及V8垃圾回收机制
[MySQL] understand the important architecture of MySQL (I)
E. Two Small Strings
Qt随手笔记(二)Edit控件及float,QString转化、
面试突击68:为什么 TCP 需要 3 次握手?
新公链Aptos何以拉满市场期待值?