当指定了参数limit=1
, 再次上传就会无效
以下是官方文档给出的解决方法示例
通过on-exceed
来定义超出限制时的行为
<template>
<el-upload
ref="uploadRef"
:limit="1"
:on-exceed="handleExceed"
:auto-upload="false"
>
</el-upload>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { genFileId } from 'element-plus'
import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus'
const uploadRef= ref<UploadInstance>()
const handleExceed: UploadProps['onExceed'] = (files) => {
uploadRef.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadRef.value!.handleStart(file)
submitUpload()
}
const submitUpload = () => {
uploadRef.value!.submit()
}
</script>
标签:el,const,upload,value,Element,file,import,uploadRef,上传
From: https://www.cnblogs.com/echohye/p/18376574