Within my code, I am storing data in the variable this.roomsData.room_photos
[ { "url": "https://api.example.com/uploads/609ee58907166.jpg" }, { "url": "https://api.example.com/uploads/609ee5898ba19.jpg" }, { "url": "https://api.example.com/uploads/609ee58994a10.jpg" }, { "url": "https://api.example.com/uploads/609ee589af635.jpg" }, { "url": "https://api.example.com/uploads/609ee589b0fc7.jpg" }, { "url": "https://api.example.com/uploads/609ee589cd79f.jpg" }, { "url": "https://api.example.com/uploads/609ee589d8d27.jpg" } ]
Additionally, I have another set of data stored in the variable this.roomsData.edit_room_photos
, which is generated through the function:
uploadRoomImages: async function (file, progress, error, options) {
try {
console.log(file, options);
const formData = new FormData()
formData.append('room_photos', file)
const result = await fetch('https://api.example.com/uploads_scripts/rooms.php', {
method: 'POST',
body: formData
})
progress(100) // (native fetch doesn’t support progress updates)
return await result.json()
} catch (err) {
error('Unable to upload file')
}
},
This component includes an input element as follows:
<FormulateInput
type="image"
name="room_photos"
v-model="roomsData.edit_room_photos"
label="Select Room Images To Upload"
help="Select a png, jpg,webp or gif to upload."
validation="required|mime:image/jpeg,image/png,image/gif,image/webp"
:uploader="uploadRoomImages"
error-behavior="live"
multiple
/>
I am wondering how to merge the data stored in this.roomsData.room_photos
with the data obtained from the function resolving in this.roomsData.edit_room_photos
without removing any duplicates. I have attempted using object assign and array concat within the form submit handler, but encountered cyclic JSON errors.
If possible, I would like to combine both arrays without eliminating duplicate entries. How can this merging process be achieved?