我在nuxt中有这样一种形式:
<v-form v-if="displayForm" ref="form" v-model="valid" enctype="multipart/form-data" lazy-validation>
<v-flex xs12 md6 sm12>
<v-text-field
v-model="linkOriginal"
label="Link to the original work (not required)"
/>
</v-flex>
<v-flex xs12 md6 sm12>
<span>Pic from original work (required)</span>
<input id="file" ref="file" type="file" @change="handleFileUpload()">
</v-flex>
</v-form>
我的脚本是这样的:
<script>
export default {
data() {
return {
file: "",
linkOriginal: "",
};
},
methods: {
handleFileUpload() {
console.log(this.$refs.file.files[0]);
this.file = this.$refs.file.files[0];
},
submit() {
if (this.$refs.form.validate()) {
let formData = new FormData();
formData.append("file", this.file);
formData.append("notifDate", this.notifDate)
this.$axios
.post(
"http://mynodeserver.com:3000/infringement",
formData,
{
headers: {
"Access-Control-Allow-Origin": true
"Content-Type": "multipart/form-data"
}
}
)
.then(response => {
this.displayForm = false;
this.displayError = false;
this.displaySuccess = true;
})
.catch(e => {
this.displayForm = false;
this.displaySuccess = false;
this.displayError = true;
});
} else {
console.log("u need to complete the required elements");
}
},
clear() {
this.$refs.form.reset();
}
}
};
</script>
在控制台日志req.body.file或req.body.notifDate的节点服务器端,它返回undefined,因此无法将其附加到要使用nodemailer发送的电子邮件中。我在这里想念什么?
答案 0 :(得分:0)
axios.post()
请求将一个对象作为第二个参数axios.post('/api/submit', {data: formData})