[Vuejs]-Upload image using vue js with form text fields

0👍

after two days this is my solution :

const formData = new FormData()
  formData.append('image', this.selectedFile, this.selectedFile.name)
  $($('form-in-question').serializeArray()).each(function (i, field) {
    formData.append(field.name, field.value)
  })
  this.$axios.$post('endpoint.com', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }).then((response) => {
    this.validation(response)
    if (response.success) { this.refresh = true }
  })

Leave a comment