当前位置:网站首页>js判断图片是否存在
js判断图片是否存在
2022-08-11 06:14:00 【Crazy_GirlLL】
1,这个方法,我用了下,同一个图片路径,vue的环境下,本地是可以的,但是不知道为什么到了正式环境,存在的图片也被判断为了false
//判断图片是否存在
function checkImgExists(imgurl) {
var ImgObj = new Image(); //判断图片是否存在
ImgObj.src = imgurl;
//存在图片
if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
return true;
} else {
return false;
}
}
2,可以使用img标签的error方法
js:onerror后面可以直接放上备用图片,也可以直接写方法
<img onerror="this.src='https://t.8kmm.com/upload/vod/20190829-1/db8b269c40172799f215aba93f03a03d.jpg';" src="https://www.88tv.org/upload/vod/20190829-1/db8b269c40172799f215aba93f03a03d.jpg" >
vue:error后面跟方法,根据变量显示别的
<img v-if="item.showImg" @error="noExistImg(item)" :src="`${constants.ICONS_CHANNEL}/${item.channel.toLowerCase()}.png`" style="width: 45px;" alt="">
<span v-else class="textLogo">{
{item.channelName.substr(0,1)}}</span>
noExistImg (record) {
this.publishAccountArr.map(item => {
if (item.id === record.id) {
item.showImg = false
}
})
}
边栏推荐
- Redis + lua implements distributed interface current limiting implementation scheme
- 为什么C#中对MySQL不支持中文查询
- 每日sql--统计员工近三个月的总薪水(不包括最新一个月)
- prometheus学习5altermanager
- 那些事情是用Unity开发项目应该一开始规划好的?如何避免后期酿成巨坑?
- Daily sql-employee bonus filtering and answer rate ranking first
- 每日sql -用户两天留存率
- STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
- Discourse's Close Topic and Reopen Topic
- 软件测试主要做什么工作,难不难?
猜你喜欢
技能在赛题解析:交换机防环路设置
HCIP WPN experiment
How to choose professional, safe and high-performance remote control software
OA project meeting notice (query & whether attending & feedback for details)
技术分享 | 实战演练接口自动化如何处理 Form 请求?
抖音API接口
Taobao sku API interface (PHP example)
JD.com product details API call example explanation
抖音获取douyin分享口令url API 返回值说明
Pinduoduo API interface (attach my available API)
随机推荐
姿态解算-陀螺仪+欧拉法
从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系
Daily sql-employee bonus filtering and answer rate ranking first
Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
2022-08-09 第四小组 修身课 学习笔记(every day)
每日sql - 判断+聚合
HCIP WPN experiment
《Show and Tell: A Neural Image Caption Generator》论文解读
prometheus学习5altermanager
2022-08-09 Group 4 Self-cultivation class study notes (every day)
下一代 无线局域网--强健性
redis + lua实现分布式接口限流实现方案
PIXHAWK飞控使用RTK
Unity程序员如何提升自己的能力
Taobao API interface reference
那些事情是用Unity开发项目应该一开始规划好的?如何避免后期酿成巨坑?
Daily sql-seek the sum of successful investments in 2016
Depth (relay supervision)
梅科尔工作室——BP神经网络
mmdetection的安装和训练、测试didi数据集的步骤(含结果)