前言:使用el-image组件预览大图,但你会发现文档中并没有写触发预览大图的方法,其实可以通过ref获取dom节点,再调用clickHandler方法进行放大预览调用
<template>
<div>
<el-button @click="tap">点击放大图片</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',
],
}
},
methods: {
tap() {
this.$refs.preview.clickHandler()
},
},
}
</script>