RT, I use vue.js + axios + formdata. But every time I post, I can only post the file file to the backend, and the parameter is always empty. I don"t know how to modify it.
my form:
<form action="" method="post" id="myForm" enctype="multipart/form-data">
<lable for="p1">p1: </lable>
<input type="text" name="p1" id="hbaseTablePut" v-model="p1">
<lable for="p2">p2: </lable>
<input type="text" name="p2" id="p2" v-model="p2" >
<label class="the-submit">
<input type="file" id="file" ref="file" v-on:change="handleFileUpload($event)">
</label>
<button v-on:click="submitFile($event)">submit</button>
</form>
script:
data(){
return{
p1:"",
p2:""
}
submitFile(event){
event.preventDefault();
let formData = new FormData();
formData.append("p1", this.p1);
formData.append("p2", this.p2);
formData.append("file", this.file);
let config = {
headers:{"Content-Type":"multipart/form-data"}
};
axios.post("/parser/upload", formData, config
).then(rst =>{
//var res = rst.data;
//this.fileUpRes = res;
console.log("SUCCESS");
})
.catch(function(){
this.fileUpRes = "failed";
console.log("FAILURE!!");
});
},
handleFileUpload(event){
event.preventDefault();
this.file = this.$refs.file.files[0];
},
every time I use formdata.append, when I receive the display in the backend (node.js) backend, only file can receive it, and the p1LGI p2 displayed is always {} empty. I don"t know what went wrong.