el-upload实现 再次上传文件覆盖前面的文件 的效果

使用Vue的el-upload组件处理文件上传及覆盖
文章讲述了如何在Vue应用中利用el-upload组件进行文件上传操作,特别是通过:on-change事件处理函数handleChange实现文件的覆盖逻辑,限制上传文件类型为.xlsx,并且限制最多只能上传2个文件。

使用 :on-change=“handleChange” 来实现文件的覆盖

 <el-upload
                class="upload-demo"
                action=""
                :http-request="uploadPicture"
                :on-preview="handlePreview"
                :on-remove="handleRemoves"
                :before-remove="beforeRemoves"
                :on-error="imgUploadError"
                :file-list="pictureList"
                :on-change="handleChange"
                list-type="xls"
                :limit="2"
                accept=".xlsx">
                <el-button size="small" type="success" :loading="notUpload" style="width:220px;">点击上传</el-button>
              </el-upload>
handleChange(file, fileList) {
        if (fileList.length > 1) {
          fileList[0] = fileList[1]
          fileList.splice(1, 1);
        }
 },
<template> <el-dialog title="导入" :visible.sync="dialogVisible" width="400px" append-to-body @close="resetDialog" :close-on-click-modal="false"> <el-form class="drawer-multiColumn-form"> <el-form-item> <el-upload class="upload-demo" drag accept=".xlsx" action="" :on-change="handleChangeUp" :before-upload="beforeAvatarUpload" :file-list="fileList" :on-exceed="handleExceed" :limit="excelLimit" :auto-upload="false"> <i class="el-icon-upload"></i> <div class="el-upload__text">将文件拖到此处,或点击<em>上传</em></div> <div class="el-upload__tip" slot="tip">只能上传exlec文件,且不超过20M</div> </el-upload> </el-form-item> </el-form> <span slot="footer" class="dialog-footer"> <el-button @click="resetDialog">取 消</el-button> <el-button type="primary" @click="handleConfirm()">保 存</el-button> </span> </el-dialog> </template> <script> export default { name: 'importMenu', props: {}, data() { return { dialogVisible: false, excelLimit: 1, fileType: ["application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], fileList: [] } }, methods: { handleOpen() { this.fileList = [] this.dialogVisible = true }, resetDialog() { this.fileList = [] this.dialogVisible = false }, beforeAvatarUpload(file) { console.log('kcowepdkeowp') // console.log('file',file) }, handleExceed() { //提示最多只能上传1个 this.$message.warning("最多上传1个文件!"); }, handleChangeUp() { }, handleConfirm() { // console.log('导入的的的额的e') // const data = await this.$Api.systemApi.viewInport(null, { // pathParams: [row.id], // }); } } } </script> 点击beforeAvatarUpload,无法获取数据做文件格式校验,只允许上传exlec
最新发布
09-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值