[Vuejs]-How to push object to existing array in Vue.js

1๐Ÿ‘

โœ…

I would suggest using v-model on the select to detect which is currently selected.

<div id="app">
  <select @change="onChange" class="form-control" v-model="selected">
   <option value="" selected disabled>Choose</option>
   <option v-for='item,key in items' :value="item">@{{ item.name }}
   </option>
</select>
<p v-for="newItem in newItems">
  {{newItem}}
</p>
</div>

and then push this.selected in your onChange method instead:

this.newItems.push(this.selected)

Hope this helps.

Working fiddle of your code with some small modifications:

https://jsfiddle.net/MapletoneMartin/e4oth98p/7/

๐Ÿ‘คMartinSRimsbo

Leave a comment