vue中用ajax上传文件

直接上代码

<input class="file-btn" type="file" @change="uploadCompany($event)" name="uploadCompany"  v-model="filename" accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>

uploadCompany: function(event){
this.file = event.target.files;
let formdata = new FormData()
formdata.append('file', this.file[0])
formdata.append('submit', false);
$.ajax({
url: api.url+"Excel/importQyInfo",
data: formdata,
type: "POST",
dataType: "json",
cache: false, //上传文件无需缓存
processData: false, //用于对data参数进行序列化处理 这里必须false
contentType: false, //必须
success: function (res) {
console.log("上传完成!",res);
},
})
}

posted @ 2019-04-02 12:44  不不abc  Views(2898)  Comments(0Edit  收藏  举报