<template> <el-upload v-model:file-list="fileList" class="upload-demo" action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" multiple :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" :limit="3" :on-exceed="handleExceed" > <el-button type="primary">Click to upload</el-button> <template #tip> <div class="el-upload__tip"> jpg/png files with a size less than 500KB. </div> </template> </el-upload> </template> <script lang="ts" setup> import { ref } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import type { UploadProps, UploadUserFile } from 'element-plus' const fileList = ref<UploadUserFile[]>([ { name: 'element-plus-logo.svg', url: 'https://element-plus.org/images/element-plus-logo.svg', }, { name: 'element-plus-logo2.svg', url: 'https://element-plus.org/images/element-plus-logo.svg', }, ]) const handleRemove: UploadProps['onRemove'] = (file, uploadFiles) => { console.log(file, uploadFiles) } const handlePreview: UploadProps['onPreview'] = (uploadFile) => { console.log(uploadFile) } const handleExceed: UploadProps['onExceed'] = (files, uploadFiles) => { ElMessage.warning( `The limit is 3, you selected ${files.length} files this time, add up to ${ files.length + uploadFiles.length } totally` ) } const beforeRemove: UploadProps['beforeRemove'] = (uploadFile, uploadFiles) => { return ElMessageBox.confirm( `Cancel the transfer of ${uploadFile.name} ?` ).then( () => true, () => false ) } </script>为什么会有默认的上传文件按钮
相关推荐

















<el-upload ref="uploadBack" list-type="picture-card" :before-upload="field103BeforeUpload" accept=".pdf"
:limit="1" :headers="uploadPdf.headers" :action="uploadPdf.url" :disabled="uploadPdf.isUploading"
:on-success="handlePdfFileSuccess">
<template slot="file" slot-scope="{ file }">
{{ file.name }}
</template>
</el-upload>在上传前判断文件名是否有空格,如果有,就去掉空格然后继续自己上传, field103BeforeUpload(file) {
if (/\s/.test(file.name)) {
const newFile = new File([file], file.name.replace(/\s/g, ''), {
type: file.type,
lastModified: Date.now()
})
this.$nextTick(() => {
this.$refs.uploadBack.uploadFiles = [] // 清空原有文件列表
this.$refs.uploadBack.handleStart(newFile)
})
return false
}
this.loadingTitle = '开始上传'
this.uploadLoading = this.$loading({
lock: true,
text: this.loadingTitle,
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
return true
},在上传成功的方法是否也需要更改handlePdfFileSuccess(response, file, fileList) {
console.log('*** file ***', file)
if (response.code === 200) {
this.loadingTitle = '上传成功'
this.uploadLoading.close()
// this.localPdfPth=file.
const newFileObj = {
url: response.data.url,
uid: file.uid, // 保留原始文件的uid
name: file.name // 如果需要,也可以保留文件名
}
this.formData.waitSignUrl.push(newFileObj)
} else {
if (this.loading != null) {
this.loading.close()
}
}
},

