[英]How to disable an already selected option in a dropdown menu?
I have 3 dropdowns and I'm trying to figure out how to disable an already chosen option. 我有3个下拉菜单,我试图弄清楚如何禁用已经选择的选项。 Regarding to this post here I tried the following:
关于这篇文章,我尝试了以下方法:
<template v-for="n in 3">
<select
v-model="user.languages[n-1]"
:key="n"
class="btn btn-secondary d-flex header-input"
>
<option
v-for="language in languages"
:key="language.id"
:id="n"
:value="language['lang_' + locale]"
:disabled="user.languages.includes(language.value)"
>{{language['lang_'+locale]}}</option>
</select>
</template>
because user.languages
returns an array. 因为
user.languages
返回一个数组。
But this doesn't seem to work at all. 但这似乎根本不起作用。 If I remove the
includes(language.value)
then everything is disabled right off the bat (obviously). 如果我删除了
includes(language.value)
那么一切就被禁用了(很明显)。
language.value a String? language.value一个字符串?
I think we should change from "language.value" to "language['lang_'+locale]" 我认为我们应该从“ language.value”更改为“ language ['lang _'+ locale]”
Have you tried it for a single dropdown and is it working properly for it? 您是否尝试过一个下拉菜单,并且可以正常使用?
Because I think if it's not working for a single just try like below: 因为我想如果它不能正常工作,请尝试如下操作:
In data(), take one variable that is an empty array and then try this: 在data()中,获取一个为空数组的变量,然后尝试以下操作:
<select v-model = "variable-name" and in option value:
<option :value="language.value">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.