简体   繁体   English

在 Vue 中启用下拉选择按钮?

[英]Enable Button on DropDown Select in Vue?

I am using the vuetify material library and i have a v-select with items assigned to it.我正在使用 vuetify 材料库,并且我有一个v-select其中分配了项目。 How can i make so that only when an item in selected that the button will get enabled?我怎样才能做到只有在选择了一个项目时才会启用按钮?

Here is a sample pen .这是一支样品

 new Vue({ el: '#app', data() { return { items: [ 'Foo', 'Bar', 'Biz', 'Buzz' ] } } })
 <script src="https://cdn.jsdelivr.net/npm/vuetify@1.5.14/dist/vuetify.min.js"></script> <link href="https://cdn.jsdelivr.net/npm/vuetify@1.5.14/dist/vuetify.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <v-app id="inspire"> <v-layout row class="ml-3"> <v-flex xs4> <v-select label="Select Something" :items="items"></v-select> </v-flex> <v-flex xs4 class="ml-3 mt-2"> <v-btn disabled>Button</v-btn> </v-flex> </v-layout> </v-app> </div>

So by default the button will be disabled, only on a select from one of the options in the dropdown will the button be enabled.因此,默认情况下该按钮将被禁用,只有在从下拉列表中的选项之一中进行选择时,该按钮才会被启用。 Thank you for the help.感谢您的帮助。

You need to bind your v-select to a variable, and then conditionally disable the button by checking the variable value, something like the following.您需要将v-select绑定到一个变量,然后通过检查变量值有条件地禁用按钮,如下所示。

See codepen .代码笔

 new Vue({ el: '#app', data() { return { items: [ 'Foo', 'Bar', 'Biz', 'Buzz' ], selectedItem: null } } })
 <script src="https://cdn.jsdelivr.net/npm/vuetify@1.5.14/dist/vuetify.min.js"></script> <link href="https://cdn.jsdelivr.net/npm/vuetify@1.5.14/dist/vuetify.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <v-app id="inspire"> <v-layout row class="ml-3"> <v-flex xs4> <v-select label="Select Something" :items="items" v-model="selectedItem"></v-select> </v-flex> <v-flex xs4 class="ml-3 mt-2"> <v-btn :disabled="selectedItem === null">Button</v-btn> </v-flex> </v-layout> </v-app> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM