| | |
| | | const uploadUrl = 'pc/requirement!ajaxAddRequirement' |
| | | |
| | | export default { |
| | | // 文件上传路径 |
| | | uploadUrl, |
| | | // 文件上传方法 |
| | | uploadFile (content) { |
| | | var formData = new FormData() |
| | | formData.append(content.filename, content.file) |
| | | Axios({ |
| | | method: 'post', |
| | | headers: { 'Content-Type': 'multipart/form-data' }, |
| | | url: content.action, |
| | | data: formData |
| | | }).then((res)=>{ |
| | | console.log('文件上传完成', res) |
| | | content.onSuccess(res.data, content) |
| | | }).catch((res)=>{ |
| | | if (res.response) { |
| | | content.onError('上传文件失败' + res.response.status + ',' + res.response.data, res) |
| | | } else if (res.request) { |
| | | content.onError('上传文件失败,服务器端无响应') |
| | | } else { |
| | | content.onError('上传文件失败,请求封装失败') |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | // 文件上传路径 |
| | | uploadUrl, |
| | | // 文件上传方法 |
| | | uploadFile(content) { |
| | | var formData = new FormData() |
| | | formData.append(content.filename, content.file) |
| | | Axios({ |
| | | method: 'post', |
| | | headers: { 'Content-Type': 'multipart/form-data' }, |
| | | url: content.action, |
| | | data: formData |
| | | }).then((res) => { |
| | | console.log('文件上传完成', res) |
| | | content.onSuccess(res.data, content) |
| | | }).catch((res) => { |
| | | if (res.response) { |
| | | content.onError('上传文件失败' + res.response.status + ',' + res.response.data, res) |
| | | } else if (res.request) { |
| | | content.onError('上传文件失败,服务器端无响应') |
| | | } else { |
| | | content.onError('上传文件失败,请求封装失败') |
| | | } |
| | | }) |
| | | } |
| | | } |