elementui上传后再次点击上传
时间: 2023-10-05 15:07:11 浏览: 36
如果你使用的是 ElementUI 的 Upload 组件,可以通过监听文件上传的状态来实现再次点击上传的功能。
具体的做法是,当文件上传成功或者上传失败时,将 Upload 组件的 fileList 属性清空,这样就可以再次选择文件并上传了。代码示例:
```
<template>
<el-upload
class="upload-demo"
ref="upload"
:action="uploadUrl"
:file-list="fileList"
:on-success="handleSuccess"
:on-error="handleError"
>
<el-button slot="trigger">选取文件</el-button>
<el-button type="primary" slot="tip">上传到服务器</el-button>
</el-upload>
</template>
<script>
export default {
data() {
return {
uploadUrl: 'your-upload-url',
fileList: []
}
},
methods: {
handleSuccess(response, file, fileList) {
// 上传成功后清空 fileList
this.fileList = []
},
handleError(error, file, fileList) {
// 上传失败后清空 fileList
this.fileList = []
}
}
}
</script>
```
这样,当文件上传成功或者上传失败时,就可以再次点击上传了。