實現上傳檔案顯示透過:limit="1" 和 :on-exceed來實現,但是這是後來版本新增的屬性和方法,最好吧elementPlus升級到最新,要不然on-exceed方法不會被呼叫。
<el-upload
ref="uploadRef"
:action="uploadFileUrl+'?name='+(downloadFileName.name)"
:headers="accessToken"
:format="['xls','xlsx']"
accept=".xls, .xlsx"
:show-file-list="false"
:limit='1'
:on-exceed="handleExceed"
:on-success="handleSuccess"
:on-change="fileListChange"
:auto-upload="false"
>
<el-button type="default">點選上傳</el-button>
</el-upload>
// 限制上傳一個檔案,重新選擇檔案替換原來的檔案
const handleExceed = (files) => {
uploadRef.value.clearFiles()
nextTick(() => {
uploadRef.value.handleStart(files[0])
})
}