使用element-ui的el-image实现图片预览

<template>
  <el-button type=“primary” @click="handlePreview">点击预览</el-button>
  <el-image 
    ref="imgPreview"
    style="width: 0px; height: 0px"
    :src="previewUrl" 
    :preview-src-list="previewList">
  </el-image>
</template>
data() {
  return {
    imgUrl: 'https://img2.baidu.com/it/u=3251542979,3065793396&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=1083',
    previewUrl: '',
    previewList: []
  }
},
methods: {
  handlePreview() {
    this.previewUrl = this.imgUrl
    this.previewList = [this.imgUrl]
    this.$nextTick(() => {
      this.$refs.imgPreview.clickHandler()
    })
  }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容