vue+axios+form表单上传excel
<template>
<div>
<form id="formData">
<input name="file" type="file" id="file">
</form>
<button @click="importEXCEL">上传文件</button>
</div>
</template>
<script>
methods:{
addFile(){
let file = $('#file')[0].files
let param = new FormData(); //创建form对象
param.append('file',file);//通过append向form对象添加数据
param.append('loginName',self.loginName)
//console.log(param.get('file')); //FormData私有类对象,访问不到,可以通过get判断值是否 传进去
axios({
method:'POST',
url:self.upLoadUrl,//上传地址
data:param,
headers:{'Content-Type':'multipart/form-data'}
}).then(function(response) {
console.log(response);
this.$f7.dialog.alert(response.data);
});
}
}
</script>
<style>
</style>