文件上传:
<div class="upload-form">
<input id="fileUpload" type="file" class="choose-file-input" v-on:change="addProject"/>
</div>
addProject: function () {
let that = this;
var formData = new FormData();
formData.append('sketchfile', $('#fileUpload')[0].files[0]);
$.ajax({
url: 'http://api.uitocode.oa.com/project/add',
type: 'POST',
cache: false,
data: formData,
processData: false,
contentType: false
}).done(function(res) {
console.log('上传成功');
}).fail(function(res) {});
}
要注意的是,文件上传,走ajax的话,contentType需要定义,不然会出错,切记!!
如果实在有问题,就本地用input直接定义上传一下试试,
参考地址:https://www.jianshu.com/p/46e6e03a0d53