Answer the question
In order to leave comments, you need to log in
How to display the text of the selected option?
I started to get acquainted with vuejs and I can’t figure out how to display the option text correctly, and not value.
Answer the question
In order to leave comments, you need to log in
data: () => ({
options: [
{ value: 69, text: 'hello, world!!' },
{ value: 187, text: 'fuck the world' },
{ value: 666, text: 'fuck everything' },
],
value: null,
}),
computed: {
selectedText() {
return (this.options.find(n => n.value === this.value) || {}).text || '';
},
},
<select v-model="value">
<option v-for="n in options" :value="n.value">{{ n.text }}</option>
</select>
<div>
Текст выбранной опции: <span>{{ selectedText }}</span>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question