Here is the complete example first: https://jsfiddle.net/3bzzpajh/
What I am trying to achieve is, to pass the whole person object to my method showSelectedDat, for some reason attaching the person object to a data attribute like: :data-person="person" changes the object to something like [object Object] which becomes useless inside my method:
<div id="app">
<select name="" id="" @change="showSelectedData($event)" >
<option :value="person.name" :data-name="person.name" v-for="person in people[0]"> {{ person.name }}</option>
</select>
</div>
As shown in the above code, I am currently "passing person" name like :data-name="person.name" but this becomes cumbersome when person has many properties.
This is where my vuejs application:
new Vue({
el: '#app',
data () {
return {
people: [{
'1': {
'code': 1010,
'name': 'sam',
'status': 'ACTIVE',
'class': 'RED',
'currencyCode': 'CHF'
},
'2': {
'code': 1210,
'name': 'jane',
'status': 'ACTIVE',
'class': 'WHiTE',
'currencyCode': 'NA'
},
'3': {
'code': 7777,
'name': 'luis',
'status': 'ACTIVE',
'class': 'BLUE',
'currencyCode': 'DE'
},
'4': {
'code': 443,
'name': 'dave',
'status': 'ACTIVE',
'class': 'GREEN',
'currencyCode': 'FR'
}
}]
}
},
methods: {
showSelectedData: function (event) {
console.log(event.target.selectedOptions[0].dataset.name)
}
}
})
So, to recape, how do I get person inside showSelectedData when a dropdown is selected?
v-modelinstead ofchange?v-modelat least not with onchange