I am attempting to showcase a fullName function using the selected value
HTML :
<div id="test">
<h1>{{ sayHello }}</h1>
<select v-model="selected">
<option v-for="person in persons" v-bind:value="person.about">
{{ person.lname }}
</option>
</select>
<p> {{ selected }} </p>
JS
New Vue({
el: '#test',
data: {
selected : '',
persons: [
{ fname: 'Foo' ,
lname : 'Foo2',
about : 'loren ipsum'},
{ fname: 'Bar' ,
lname:'Bar2',
about: 'dolor met'}
]
},
computed :{
sayHello : function() {
return this.selected.fname + " " + this.selected.lname
}
}
})
h1 should return based on selected object value, this code returns undefined,(doesnt run at all if I pass in selected as arg) although the other parts work.Im not sure how to get the computed function to reference the selected object?
Edit:After using the great suggestions,Added a codepen for anyone else who is just starting: