Vue.js Form multipart/form-data v-model array example

If you are submitting a form that uses multipart/form-data, then you probably have a field that is also an array. This is an example of how to use a v-model array to store an array of inputs.

HTML

<div id="app">
  <form action="post">
    <input type="text" name="names[]" v-model="names[0]">
    <input type="text" name="names[]" v-model="names[1]">
    <input type="text" name="names[]" v-model="names[2]">
    <input type="text" name="names[]" v-model="names[3]">
  </form>
  {{ names | string }}
</div>

JavaScript

var app = new Vue({
  el: "#app",
  data: {
    names: []
  }
});