V
V
Vadim Sutormin2020-07-14 12:33:44
Vue.js
Vadim Sutormin, 2020-07-14 12:33:44

How to get the selected option from a SELECT in a component in VUE.JS?

There is a component in the select component with a list,
<Enums v-model="orgs"></Enums>

<select :value="value">
<option value="1">Организация 1</option>
<option value="2">Организация 2</option>
</select>

When the page loads, the organization comes out as needed, according to org.
But how can I make org change when I select a different value in the select? Selected value is not passed to parent component

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-07-14
@Wunder

When changing the value of the select, you must send the new value to the parent.
Add a select @input="$emit('input', $event.target.value)", or make it a computed property:

innerValue: {
  get() {
    return this.value;
  },
  set(val) {
    this.$emit('input', val);
  },
},

<select v-model="innerValue">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question