1. Image图片

1.1. Image图片容器, 在保留原生img的特性下, 支持懒加载, 自定义占位、加载失败等。

1.2. Attributes

参数

说明

类型

可选值

默认值

src

图片源, 同原生

string

fit

确定图片如何适应容器框, 同原生object-fit

string

fill / contain / cover / none / scale-down

alt

原生alt

string

referrer-policy

原生referrerPolicy

string

lazy

是否开启懒加载

boolean

false

scroll-container

开启懒加载后, 监听scroll事件的容器

string / HTMLElement

最近一个 overflow值为auto或scroll的父元素

preview-src-list

开启图片预览功能

Array

z-index

设置图片预览的z-index

Number

2000

1.3. Events

事件名

说明

回调参数

load

图片加载成功触发

(e: Event)

error

图片加载失败触发

(e: Error)

1.4. Slots

名称

说明

placeholder

图片未加载的占位内容

error

加载失败的内容

2. Image图片例子

2.1. 使用脚手架新建一个名为element-ui-image折叠面板的前端项目, 同时安装Element插件。

2.2. 编辑index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import Image from '../components/Image.vue'
import PlaceholderImage from '../components/PlaceholderImage.vue'
import ErrorImage from '../components/ErrorImage.vue'
import LazyImage from '../components/LazyImage.vue'
import PreviewImage from '../components/PreviewImage.vue'Vue.use(VueRouter)const routes = [{ path: '/', redirect: '/Image' },{ path: '/Image', component: Image },{ path: '/PlaceholderImage', component: PlaceholderImage },{ path: '/ErrorImage', component: ErrorImage },{ path: '/LazyImage', component: LazyImage },{ path: '/PreviewImage', component: PreviewImage }
]const router = new VueRouter({routes
})export default router

2.3. 在components下创建Image.vue

<template><div><h1>基础用法</h1><h4>可通过fit确定图片如何适应到容器框, 同原生object-fit。</h4><div class="imgContainer" v-for="fit in fits" :key="fit"><span class="title">{{ fit }}</span><el-image style="width: 100px; height: 100px;" :src="url" :fit="fit"></el-image></div></div>
</template><script>
export default {data () {return {fits: ['fill', 'contain', 'cover', 'none', 'scale-down'],url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'}}
}
</script><style scoped>.imgContainer {display: inline-block;width: 200px;text-align: center;}.title {display: inline-block;width: 100%;}
</style>

2.4. 在components下创建PlaceholderImage.vue

<template><div><h1>占位内容</h1><h4>可通过slot = placeholder可自定义占位内容。</h4><div class="imgContainer"><span class="title">默认</span><el-image :src="src" style="width: 300px; height: 300px;"></el-image></div><div class="imgContainer"><span class="title">自定义</span><el-image :src="src" style="width: 300px; height: 300px;"><div slot="placeholder">加载中<span>...</span></div></el-image></div></div>
</template><script>
export default {data () {return {src: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg'}}
}
</script><style scoped>.imgContainer {display: inline-block;width: 400px;text-align: center;}.title {display: inline-block;width: 100%;}
</style>

2.5. 在components下创建ErrorImage.vue

<template><div><h1>加载失败</h1><h4>可通过slot = error可自定义加载失败内容。</h4><div class="imgContainer"><span class="title">默认</span><el-image style="width: 150px; height: 150px;"></el-image></div><div class="imgContainer"><span class="title">自定义</span><el-image style="width: 150px; height: 150px; background-color: #F5F7FA;"><div slot="error" style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center;"><i class="el-icon-picture-outline"></i></div></el-image></div></div>
</template><style scoped>.imgContainer {display: inline-block;width: 200px;text-align: center;}.title {display: inline-block;width: 100%;}
</style>

2.6. 在components下创建LazyImage.vue

<template><div><h1>懒加载</h1><h4>可通过lazy开启懒加载功能, 当图片滚动到可视范围内才会加载。可通过scroll-container来设置滚动容器, 若未定义, 则为最近一个overflow值为auto或scroll的父元素。</h4><div class="image-lazy"><el-image v-for="url in urls" :key="url" :src="url" lazy></el-image></div></div>
</template><script>
export default {data () {return {urls: ['https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg','https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg','https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg','https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg','https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg','https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg','https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg']}}
}
</script><style scoped>.image-lazy {width: 400px;height: 400px;overflow-y: auto;}.image-lazy .el-image {display: block;min-height: 200px;margin-bottom: 30px;}.image-lazy .el-image:last-child {margin-bottom: 0;}
</style>

2.7. 在components下创建PreviewImage.vue

<template><div><h1>大图预览</h1><h4>可通过previewSrcList开启预览大图的功能。</h4><el-image style="width: 100px; height: 100px" :src="url" :preview-src-list="srcList"></el-image></div>
</template><script>
export default {data () {return {url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',srcList: ['https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg','https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg']}}
}
</script>

2.8. 运行项目, 访问http://localhost:8080/#/Image

2.9. 运行项目, 访问http://localhost:8080/#/PlaceholderImage

2.10. 运行项目, 访问http://localhost:8080/#/ErrorImage

2.11. 运行项目, 访问http://localhost:8080/#/LazyImage

2.12. 运行项目, 访问http://localhost:8080/#/PreviewImage

049_Image图片相关推荐

  1. Python+OpenCV 图像处理系列(1)— Ubuntu OpenCV安装、图片加载、显示和保存

    Ubuntu 16.04 下安装 Opencv sudo apt-get install libopencv-dev sudo apt-get install python-opencv 或者使用 p ...

  2. FastAI 课程学习笔记 lesson 1:宠物图片分类

    文章目录 代码解析 神奇的"%" 导入fastAI 库 下载解压数据集 untar_data 获取帮助文档 help() ? ?? doc 设置路径 get_image_files ...

  3. 1 用python进行OpenCV实战之用OpenCV3实现图片载入、显示和储存

    code 将下面文档存为load_display_save.py #-*- coding:utf-8 -*- from __future__ import print_function #1 impo ...

  4. java 16进制与图片互转

    十六进制转成图片 /*** 十六进制转成图片* @author Administrator**/public static void saveToImgFile(String src,String o ...

  5. ttf,woff2字体转化为png图片,python读取图片

    20210326 乱码转换的时候 是同一套unicode编码 但是在不同的字体库中对应的字不同 20210324 https://jingyan.baidu.com/article/e73e26c0c ...

  6. LeetCode简单题之图片平滑器

    题目 包含整数的二维矩阵 M 表示一个图片的灰度.你需要设计一个平滑器来让每一个单元的灰度成为平均灰度 (向下舍入) ,平均灰度的计算是周围的8个单元和它本身的值求平均,如果周围的单元格不足八个,则尽 ...

  7. Typora+PicGo图床配置(本地图片-->网络url~博客必备)

    前段时间搭了一个hexo博客,但是发现了一个很大的问题,在Typora里编辑你的博文的时候,插入的图片都是一些本地图片,然后部署的时候根本不能加载这些图片~~ 其中一个解决方法就是通过一些平台,像知乎 ...

  8. OFRecord 图片文件制数据集

    OFRecord 图片文件制数据集 在 OFRecord 数据格式 和 加载与准备 OFRecord 数据集 中,分别学习了 OFRecord 数据格式,以及如何将其它数据集转为 OFRecord 数 ...

  9. CVPR2020论文解读:CNN合成的图片鉴别

    CVPR2020论文解读:CNN合成的图片鉴别 <CNN-generated images are surprisingly easy to spot- for now> 论文链接:htt ...

最新文章

  1. 切记!MySQL中ORDER BY与LIMIT 不要一起用,有大坑
  2. Jquery调用webService的四种方法
  3. 使用HtmlHelper 写自己的 mvc 分页
  4. Nodejs Hello world benchmark
  5. 0xc000000f 由于系统注册表文件丢失或损坏,因此Windows无法加载
  6. Intel Realsense 处理帧时报错:RuntimeError: null pointer passed for argument frame_ref
  7. QT的QDial类的使用
  8. python mysql autocommit_MySQLdb autocommit的坑
  9. 小家电的精致生活幻想,都在闲鱼上被粉碎了
  10. 使用队列(Queue)解决简单的并发问题
  11. diamond专题(一)– 简介和快速使用
  12. 计算机组成原理第5版第六章答案,计算机组成原理第六章答案.docx
  13. python程序设计基础董付国 pdf-董付国《Python程序设计基础 第2版》PDF
  14. 【转载】log4j日志
  15. count时结果 hive_关于hive中的count的用法(一)
  16. 游戏逆向-CSGO逆向透视自瞄分析技巧
  17. 孙德棣38岁中秋辞世
  18. 下载与安装nexus3
  19. 虚拟机无法玩腾讯游戏该怎么办
  20. TreeView控件介绍

热门文章

  1. [Usaco2007 Oct] Super Paintball超级弹珠
  2. 《精通Linux设备驱动程序开发》——1.7 编译内核
  3. jquery高版本全选与全部选无法正常工作
  4. 智能路由器操作系统OpenWrt
  5. 阿里巴巴分布式服务框架 Dubbo 团队成员梁飞专访
  6. Pair Poject 1 【新双人贪吃蛇】本组:龚逸 合作者:庞俊
  7. BGP边界网关协议线路优势
  8. 选高防服务器要注意哪些方面?——微云网络
  9. YII1 MVC初认识(二)
  10. C#中的快捷键,可以更方便的编写代码