Commit 02906955 authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

fix formdata

parent 8f5824af
......@@ -183,7 +183,7 @@
color="blue darken-1"
text
type="submit"
@click="dialog2 = false; createPost();"
@click="dialog2 = false;"
>
Save
</v-btn>
......
......@@ -71,6 +71,7 @@
label="File input"
small-chips
dense
accept="image/*"
multiple
/>
</v-col>
......@@ -276,7 +277,7 @@
>
<v-card>
<v-card-title>
<span class="text-h5">CREAT PRODUCT</span>
<span class="text-h5">EDIT PRODUCT</span>
</v-card-title>
<v-card-text>
<v-container>
......@@ -323,7 +324,6 @@
small-chips
dense
multiple
:state="Boolean(images)"
/>
</v-col>
<v-col cols="12">
......@@ -407,7 +407,7 @@
color="blue darken-1"
text
type="submit"
@click="dialog3 = false; editProduct();"
@click="dialog3 = false; updateProduct();"
>
Save
</v-btn>
......@@ -758,6 +758,9 @@ export default {
quantity: ''
}
],
color: '',
size: '',
quantity: '',
dialog1: false,
dialog2: false,
dialog3: false,
......@@ -790,6 +793,7 @@ export default {
href: '/products'
}
],
i: '',
products: [],
product: [],
categories: [],
......@@ -945,15 +949,19 @@ export default {
},
createProduct () {
const self = this
// const set = new Set([this.images])
// const images = Array.from(set)
const fd = new FormData()
fd.append('name', this.name)
fd.append('price', this.price)
fd.append('category_id', this.category_id)
fd.append('description', this.description)
fd.append('image', this.images)
fd.append('variants', this.variants)
for (let i = 0; i < this.variants.length; i++) {
fd.append(`variants[${i}][color]`, this.variants[i].color)
fd.append(`variants[${i}][quantity]`, this.variants[i].quantity)
fd.append(`variants[${i}][size]`, this.variants[i].size)
}
for (let j = 0; j < this.images.length; j++) {
fd.append(`images[${j}]`, this.images[j])
}
this.$axios
.post('/products/',
fd
......@@ -1039,16 +1047,23 @@ export default {
},
updateProduct (ID) {
const self = this
const fd = new FormData()
fd.append('name', this.eName)
fd.append('price', this.ePrice)
fd.append('category_id', this.eCategoryId)
fd.append('description', this.eDescription)
for (let i = 0; i < this.eVariants.length; i++) {
fd.append(`variants[${i}][color]`, this.eVariants[i].color)
fd.append(`variants[${i}][quantity]`, this.eVariants[i].quantity)
fd.append(`variants[${i}][size]`, this.eVariants[i].size)
}
for (let j = 0; j < this.eImages.length; j++) {
fd.append(`images[${j}]`, this.eImages[j])
}
try {
this.$axios
.post(`/products/update/${this?.eId}`, {
name: this.eName,
price: this.ePrice,
category_id: this.eCategoryId,
description: this.eDescription,
images: this.eImages,
variants: this.eVariants
}, {
.post(`/products/update/${this?.eId}`,
fd, {
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment