1

Hy I'm creating a simple dropdown using bootstrap-vue in vuejs. The Code in my component is like this :

<b-col sm="2">
   <b-dropdown :text="selectedItem" v-model="selectedItem">
       <b-dropdown-item>Action</b-dropdown-item>
       <b-dropdown-item>Another action</b-dropdown-item>
       <b-dropdown-item>Something else here</b-dropdown-item>
   </b-dropdown>
   {{selectedItem}}
</b-col>
...
...
...
data () {
 return {
   selectedItem: ''
 }
}

The problem is I can't select any item from dropdown item. Is there something that I missed here ? Thanks in advance

Reference : https://bootstrap-vue.js.org/docs/components/dropdown

4

2 回答 2

5

这是导航的下拉菜单,而不是select表单的元素。它不支持 v-model 并且不像表单输入。

您可以使用select来代替,或者如果您仍想使用下拉菜单作为表单选择,您可以添加点击处理程序来控制它。

例如

<b-dropdown :text="selectedItem">
        <b-dropdown-item @click="selectedItem='Action'">Action</b-dropdown-item>
        <b-dropdown-item @click="selectedItem='Another action'">Another action</b-dropdown-item>
        <b-dropdown-item @click="selectedItem='Something else here'">Something else here</b-dropdown-item>
</b-dropdown>

https://codesandbox.io/s/zky4j0zx94

于 2018-03-28T02:48:04.523 回答
2

我不认为 ab-dropdown做你认为它做的事情。

Bootstrap 下拉菜单就像菜单。他们没有v-models

您似乎需要的是一个表单选择

<b-col sm="2">
    <b-form-select v-model="selectedItem">
        <option value="Action">Action</option>
        <option value="Another action">Another action</option>
        <option value="Something else here">Something else here</option>
    </b-form-select>
    <div>selectedItem: <strong>{{ selectedItem }}</strong></div>
</b-col>
...
...
...
data () {
 return {
   selectedItem: ''
 }
}
于 2018-03-28T02:45:10.967 回答