I have a problem, I really confused about how to get value from form binding vue js. I have tried --> https://v2.vuejs.org/v2/guide/forms.html#Select. But I always getting error such as --> Property or method "selected" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. What's wrong with my code ?
Here is my code :
data: function() {
return {
data: {
options: {},
selected: ''
}
};
},
methods: {
Search: function() {
var vm = this;
var types = [
{
"id": "id",
"value": "ID"
},
{
"id": "title",
"value": "Title"
},
{
"id": "category",
"value": "Category"
},
{
"id": "username",
"value": "Nama User"
}
];
vm.data.options = types;
console.log(vm.data.selected);
}
}
Here is my html code :
<select v-model="selected" class="form-control sl">
<option v-for="option in data.options" v-bind:value="option.id">
{{ option.value }}
</option>
</select>