【发布时间】:2021-06-21 22:07:27
【问题描述】:
我有这个引导下拉菜单here。我想要做的是仅在展开下拉菜单时将按钮的背景颜色更改为蓝色。我通过向按钮添加单击侦听器来设置它的样式来实现它,但问题是当菜单展开并且用户单击其他地方时,菜单会在按钮仍为蓝色时隐藏。如何修改它,使按钮在菜单展开时为蓝色仅且仅?
这是我的代码:
//template
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" :style="test ? clickedBtn : null" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @click="testing()">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
//script
data: {
test: false,
clickedBtn: {
background: "blue",
color: "white"
}
},
methods: {
testing(){
this.test = !this.test
}
}
【问题讨论】:
-
如何使用
#dropdownMenuButton[aria-expanded="true"]作为选择器直接从开关设置样式并从中添加颜色和背景颜色? -
我们想改变
class="dropdown"而不是#dropdownMenuButton的背景颜色
标签: javascript html vue.js bootstrap-4 drop-down-menu