vue中的图片加载与显示默认图片
2017-03-16 10:52
369 查看
HTML:
JS:
针对尺寸不统一的:先显示默认图片,加载成功时移除默认图片,填充背景。
<div class="content-show-img"> <div class="show-img"> <img class="default-image" :src="data.image" @load="successLoadImg" @error="errorLoadImg"> </div> </div>
JS:
Vue.prototype.successLoadImg = function(event) { if (event.target.complete == true) { event.target.classList.remove("default-image");; var imgParentNode = event.target.parentNode; if(imgParentNode.classList.contains('show-img')==true){ imgParentNode.style.background = "#000"; } } }; Vue.prototype.errorLoadImg = function(event) { event.target.classList.add("default-image");; };
针对尺寸不统一的:先显示默认图片,加载成功时移除默认图片,填充背景。
相关文章推荐
- vue + vuelazyload图片懒加载 + 显示默认图片 (视频门户网站)
- vue图片加载与显示默认图片实例代码
- vue--当从后台加载的图片出错时显示默认的图片
- Flex中Image加载图片出错时显示默认图片的几种方法
- 转载-当图片加载失败或者没有的情况下显示默认图片
- Glide加载圆形图片第一次只显示默认图片
- Vue.js项目中,当图片无法显示时则显示默认图片
- fresco 使用的时候出现图片闪烁,先打开默认的图片然后再显示要加载的图片
- html img 加载错误时显示默认图片
- 图片路径加载失败,火狐浏览器默认显示断裂图片
- 图片加载失败显示默认图片
- js处理img标签加载图片失败,显示默认图片
- 图片加载失败,显示默认图片
- img标签中的图片加载异常时显示默认的图片
- Flex中Image加载图片出错时显示默认图片的几种方法
- 加载图片失败后显示系统默认图片
- 使用jquery给加载失败的img元素显示默认图片
- JS图片加载失败显示默认图片
- 开端——Glide加载图片至圆形控件上初次显示时是默认图片
- img标签中的图片加载异常时显示默认的图片