elementUI el-upload上传图片 并使用el-image预览

明阳旭
2023-12-01
<template>
  <div>
    <el-upload action="#" list-type="picture-card" :auto-upload="false">
      <i slot="default" class="el-icon-plus"></i>
      <div slot="file" slot-scope="{file}">
        <el-image id="122" ref="previewImg" :src="file.url" :preview-src-list='imgs'></el-image>
        <span class="el-upload-list__item-actions">
          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
            <i class="el-icon-zoom-in"></i>
          </span>
          <span class="el-upload-list__item-delete" @click="handleRemove(file)">
            <i class="el-icon-delete"></i>
          </span>
        </span>
      </div>
    </el-upload>
  </div>
</template>

<script>
export default {
  name: "uploadImgComponent",
  components: {},
  data() {
    return {
      imgs: ['http://**********/img/1.jpeg']
    }
  },
  created() {
  },
  methods: {
    handlePictureCardPreview(file) {
    	// 重点
      this.$refs.previewImg.showViewer = true
    },
    handleRemove(file) {
    }
  }
}
</script>
 类似资料: