基于ElementUI的单文件上传组件

本文档介绍了如何基于ElementUI的单文件上传组件进行二次开发,以添加删除功能。内容包括组件背景介绍,说明了组件未设置v-model,取值方式是通过ref获取图片的base64编码。提供了具体的代码实现。
摘要由CSDN通过智能技术生成

背景

ElementUI自带一个单文件选择的组件。但是该组件没有删除功能。
此处基于此组件进行二次开发。

说明

没有设置v-model,取值时使用ref取值
取值时,通过this.$refs.[ref值].img获取到图片信息
其中base64String为图片的base64编码,需要原生file文件的请自行修改源码

代码

// 单文件上传组件,通过ref取值

<template>
  <el-upload class="one-file-up" :style="fixStyle" :accept="accept" action="111" :show-file-list="false" :before-upload="checkImg" :on-change="handleImgChange" :on-remove="handleImgRemove" :auto-upload="false">
    <div class="slot-div" v-show="!img.hadUp">
      <slot name="header"></slot>
    </div>
    <img v-if="img.hadUp" :src="img.base64String">
    <i v-else class="el-icon-plus"></i>
    <i v-if="img.hadUp" class="el-icon-delete" :style="delFixStyle" @click="deleteImg"></i>
    <div class="slot-div" v-show="!img.hadUp">
      <slot name="bottom">
        <label class="slot-label"></label>
      </slot>
    </div>
  </el-upload>
</template>

<script>
export default {
   
  name: 'oneFileUp',
  props: {
   
    maxSize: {
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值