//获取数组最后一个元素 let hasFiles = files[Object.keys(files).pop()] // 参考上面的图片 let file = hasFiles.url let name = hasFiles.file.name let type = hasFiles.file.type function base64ToBlob(urlData, type) { let arr = urlData.split(','); let mime = arr[0].match(/:(.*?);/)[1] || type; // 去掉url的头,并转化为byte let bytes = window.atob(arr[1]); // 处理异常,将ascii码小于0的转换为大于0 let ab = new ArrayBuffer(bytes.length); // 生成视图(直接针对内存):8位无符号整数,长度1个字节 let ia = new Uint8Array(ab); for (let i = 0; i < bytes.length; i++) { ia[i] = bytes.charCodeAt(i); } return new Blob([ab], { type: mime }); } if (hasFiles.file.size > 1024 * 1024 * 10) { throw '文件超过10M' } let conversions = base64ToBlob(file, type) let param = new FormData() // 没给好一个值 param.append('file', file, name) 改为param.append('file', conversions, name) param.append('file', conversions, name) param.append('chunk', '0') axios.post(config.api.upload, param).then(function (res) { if (res.status === 200) { //后端判断文件大小 if (res.data && res.data.state === 'ERROR') { throw res.data && res.data.msg; } console.log(res) } });