Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140161

upload image using vue js with form text fields

$
0
0

I started wotking on small project using Vue Js and i would like to add an upload file option in my contact form, i use serialize for the form because i have a lot of input text fields. but it doesn't work with append function. how can i add upload file to my serialized form

This is my code :

addProducts () {
  const formData = $('#add-product').serialize()
  // formData.append('image', this.selectedFile, this.selectedFile.name)
  this.$axios.$post('http://endpoint.quicknsales.com/api/Product', formData).then((response) => {
    this.validation(response)
    if (response.success) { this.refresh = true }
  })
}

a part of my HTML code :

<div class="form-group mb-2">
                    <div class="row">
                      <div class="col-md-6">
                        <label class="mb-0"><strong>Buying Price:</strong></label>
                        <input
                          id="product_buying_price"
                          v-model="formFields.product_buying_price"
                          type="text"
                          class="form-control rounded-0"
                          placeholder="Product Buying Price"
                          name="general[product_buying_price]">
                      </div>
                      <div class="col-md-6">
                        <label class="mb-0"><strong>Selling Price:</strong></label>
                        <input
                          id="product_selling_price"
                          v-model="formFields.product_selling_price"
                          type="text"
                          class="form-control rounded-0"
                          placeholder="Product Selling Price"
                          name="general[product_selling_price]">
                        <input id="file" type="file" name="general[file]">
                      </div>
                    </div>
                  </div>

how can i add the upload file to my form, as you can see i have already used append function but it doesn't works


Viewing all articles
Browse latest Browse all 140161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>