【发布时间】:2020-03-29 12:33:23
【问题描述】:
我有一个使用 Vuetify 的表单,它接收文本和几张图像。如果我不包含图像,则该表单有效,但使用它们,我会收到错误 GET http://danza.test/thumbnails[object%20File] 404 (Not Found)。
如何在表单中与侧边文本一起传递图像?
部分表单处理输入:
<v-row>
<v-col cols="12" sm="6" md="6">
<v-file-input v-model="editedItem.image" label="Picture"></v-file-input>
</v-col>
<v-col cols="12" sm="6" md="6">
<v-file-input v-model="editedItem.thumbnail" label="Thumbnail"></v-file-input>
</v-col>
</v-row>
项目对象
editedItem: {
name: '',
image: null,
thumbnail: null,
species: '',
tag: '',
patreon: '',
action: '',
},
defaultItem: {
name: '',
image: null,
thumbnail: null,
species: '',
tag: '',
patreon: '',
action: '',
},
上传功能
saveToServer () {
if (this.editedIndex > -1) {
// Edit item
Object.assign(this.images[this.editedIndex], this.editedItem);
axios.put('/api/gallery/' + this.images[this.editedIndex].id, this.editedItem).then((response) => {
})
.catch(function (error) {
console.log(error);
})
} else {
//New item
let $updatedGallery = this;
let $index = this.images.push(this.editedItem)-1;
axios.post('/api/gallery', this.editedItem, {headers: {'Content-Type': 'multipart/form-data'}})
.then((response) => {
$updatedGallery.editedItem.id = response.data.id;
Object.assign($updatedGallery.images[$index], $updatedGallery.editedItem);
})
.catch(function (error) {
console.log(error);
});
}
【问题讨论】:
标签: javascript laravel vue.js