0

I am struggling to validate my data that has images using vue js and vform. My problem is, I am getting an error app.js:2137 Uncaught (in promise) TypeError: objectToFormData is not a function. How to rectify this: In Vue

      saveImageData(){
              var self=this;
              const config = {
                    headers: { 'content-type': 'multipart/form-data' }
                }
                document.getElementById('upload-file').value=[];
                let formData = new FormData();
                formData.append('title', this.form.title);
                formData.append('price', this.form.price);
                for(let i=0;i<this.form.images.length;i++){
                 formData.append('images[]', this.form.images[i]);
                }
            this.form.submit('post', '/senddata', {
              // Transform form data to FormData
              transformRequest: [function (formData, headers) {
                return objectToFormData(formData)
              }],

In app.js

    window.Vue = require('vue');
    import { Form, HasError, AlertError } from 'vform'
    import {objectToFormData} from 'object-to-formdata'
    window.Form=Form;
    window.objectToFormData=objectToFormData;

2
  • Did you import objectToFormData like you did in app.js? Commented Feb 13, 2021 at 12:11
  • @Adam I ran npm install then imported in app.js. In my backend am using Laravel controller Commented Feb 13, 2021 at 13:15

1 Answer 1

0

In case someone is having a similar problem i just replaced objecttoformdata with serialize in app js and vue template

import {serialize} from "object-to-formdata";
window.serialize=serialize;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.