【发布时间】:2022-01-18 20:12:20
【问题描述】:
试图通过这个函数插入表单数据。
这是我的功能:
saveTimeline() {
let formData = new FormData();
formData.append("title", this.title);
formData.append("from", this.from);
formData.append("to", this.to);
formData.append("events[0].year", this.year);
formData.append("events[0].image", this.softCopyUpload);
formData.append("events[0].content", this.content);
formData.append("events[0].audio", this.audioFile);
console.log(formData);
this.$axios
.post(this.$API + "api/v1/admin/timelines/", formData, {
headers: {
Authorization: "Bearer " + this.token,
},
})
.then((res) => {
if (res) {
console.log("success");
}
});
},
错误:“时间轴标题不得设置为空”
总是收到此错误。为什么?
为什么附加不起作用?
我的 JSON
{
"title": "dvdvds",
"from": 1990,
"to": 2010,
"events": [
{
"year": 1990,
"image": "test.jpg",
"content": "test content",
"audio": "test.mp4"
}
]
}
【问题讨论】:
-
有没有其他不使用formData.append()的方式上传文件?