第一种:(使用elementUi官网文档中的组件)一般项目中需要点击触发事件才进行查看大图,elementUi组件库中并没有写触发需要执行的代码,这里在触发的方法中加this.$refs.preview.clickHandler()触发查看大图功能
文章来源:https://www.toymoban.com/news/detail-524798.html
<template>
<!-- 图片预览方法一 -->
<div class="demo-image__preview">
<el-button @click="onPreview">预览</el-button>
<el-image
style="width: 100px; height: 100px"
ref="preview"
: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/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg",
],
};
},
components: {},
methods: {
onPreview() {
this.$refs.preview.clickHandler();
},
},
};
</script>
<style></style>
第二种:( 使用el-image-viewer组件,是elementUi自带的但官网文档中可能因不兼容IE没有把它暴露出来,不需要下载包引入即可)文章来源地址https://www.toymoban.com/news/detail-524798.html
<template>
<div>
<el-button @click="onPreview">预览</el-button>
<el-image
style="width: 100px; height: 100px"
ref="preview"
:src="url"
:preview-src-list="srcList"
></el-image>
<el-image-viewer
v-if="showViewer"
:on-close="closeViewer"
:url-list="srcList"
/>
</div>
</template>
<script>
import ElImageViewer from "element-ui/packages/image/src/image-viewer";
export default {
components: { ElImageViewer },
data() {
return {
showViewer: false,
url: "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
srcList: [
"https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
"https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg",
"https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg",
],
};
},
methods: {
onPreview() {
this.showViewer = true;
},
closeViewer() {
this.showViewer = false;
},
},
};
</script>
<style></style>
到了这里,关于elementUi 通过点击预览按钮实现 预览大图previewSrcList(两种方式)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!