viewer(图片查看器)

随着版本的更新Element UI新增了新的组件,例如:,没错今天被我发了Image下面可通过 previewSrcList 开启预览大图的功能。

这是官方文档中有写的,但是我想不使用Image组件又想使用预览大图的功能是否可行呢?

答案是当然可以。

使用方法

翻看了Image的源码,发现大图预览是一个小组件image-viewer,打开看看它的props,如下

props: { urlList: { type: Array, default: () => [] }, zIndex: { type: Number, default: 2000 }, onSwitch: { type: Function, default: () => {} }, onClose: { type: Function, default: () => {} } }

我们需要使用到的就只有urlList与onClose两个属性 ,一个用来放图片链接一个用来关闭查看器。

需要使用的属性我们知道了,然后我们就在代码里面引入image-viewer就可以直接使用。

<template> <div> <el-button @click="onPreview">预览</el-button> <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="[url]" /> </div> </template> <script> // 导入组件 import ElImageViewer from 'element-ui/packages/image/src/image-viewer' export default { name: 'Index', components: { ElImageViewer }, data() { return { showViewer: false, // 显示查看器 url:'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg' } }, methods: { onPreview() { this.showViewer = true }, // 关闭查看器 closeViewer() { this.showViewer = false } } </script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4f722becc6addfa699af668e01b64e53.html