[Vuejs]-How to post select input option value with axios.post?

0๐Ÿ‘

โœ…

  1. Define data for each value
data() {
  return {
     ...
     oc_id: '',
     sub_id: '',
  }
}
  1. Bind datas to inputs using v-model
<select v-model="oc_id" multiple class="form-control">
    <option v-for="(oclist , index) in oclists" :key="oclist.id" :value="oclist.id">{{ oclist.name }}</option>
</select>
...
<select  v-model="sub_id" multiple class="form-control" v-if="sublists.length>0">
   <option v-for="(sublist , index) in sublists" :key="sublist.id" :value="sublist.id">{{ sublist.name }}</option>
</select>
  1. Use data everywhere you want
addMatch() {
  axios.post("/ocs", {
      oc_id: this.oc_id,
      sub_id: this.sub_id
  })
  ...
}

Leave a comment