过去多啦不再A梦2017-05-19 10:15:15
利用beforeUpload将要上传的东西存到store里面(state也可以),最后return false,阻止上传。
<Dragger
name="ver_file"
action="version_add"
showUploadList
disabled={activeRow.id !== 0}
fileList={fileList}
onRemove={() => {
// 清空文件列表
dispatch({
type: 'SystemSettings/Version/changeFileList',
payload: {
file: {},
fileList: [],
},
});
}}
beforeUpload={(curFile, curFileList) => {
// 将上传的东西存到store里,返回false阻止上传
dispatch({
type: 'SystemSettings/Version/changeFileList',
payload: {
file: curFile,
fileList: curFileList,
},
});
return false;
}}
>
提交的时候,将file追加到FormData里面
const data = new FormData();
// 循环把字段全部加进去
Object.entries(values).forEach((item) => {
data.append(item[0], item[1] || '');
});
data.append('ver_file', file);
dispatch({
type: 'SystemSettings/Version/submitData',
payload: data,
});