(红色边框为上次上传之前的文件名显示的地方)
1.清空各个地方的fileList,
包括:新增确认、关闭页面按钮、取消关闭页面等地方设置
this.fileList=[]
2.给upload的表单处绑定动态的key值
上诉方法无效,该清空的地方都试过了, 仍显示文件名,
由于本地缓存中仍有上传之后的数据,所有页面会显示,
给upload的表单处绑定动态的key值,定义方法,给其绑定的key值赋值为随机数,在需要清空的地方调用此方法
HTML
<a-form-model-item label="附件文件" v-show="showUpload"
style="min-height: 50px; height: 50px" :key="fileKey">
<a-upload :multiple="true" :action="actionUrl" :before-upload="beforeUpload" @change="onSuccess">
<div v-if="fileList.length < 1">
<a-button>
<a-icon type="upload"/>
</a-button>
</div>
</a-upload>
</a-form-model-item>
JS
data:{
fileList:[],
showUpload:true,
// 随机key
fileKey:'',
}
methods:{
// 解决文件上传页面未清空的问题
addAgreement(){
this.fileKey=Math.random()
console.log(this.fileKey,'随机数--------');
this.fileList=[]
this.defaultsFileList=[]
},
}
本处是antd中树——右键菜单——新增页——上传文件调用的页面清空问题
onContextMenuClick(menuKey) {
var that = this
console.log(`menuKey: ${menuKey}`);
if (menuKey == 1) {
this.addAgreement()
console.log(that.form, 'form 是啥');
} else if (menuKey == 2) {
}
},