NielsNumbers's avatar

Vue Form With File Uploads?

I am using the form object approach from https://laracasts.com/series/learn-vue-2-step-by-step/episodes/19

However, I also have file uploads in my form. Instead of data.set(field, this[field]); I need to call something like data.append('coverImage', this.cover); or

   if(this.images.length > 0){
      this.images.forEach(function(image){
        data.append('gallery[]', image);
      });
    }

Any ideas how to modify form so it can handle also file uploads?

Only idea that I had was to modify the form object:

 new Form({ 
  data: {
    title: '',
    name: ''
   _method: '',	  
},
  files: {
  cover: null,
  images: [],
 }
  });

and then to access everything to form.data.title or form.files.cover etc.

But not sure if this is the best way.

0 likes
0 replies

Please or to participate in this conversation.