一个div中有 五个button ,包括1m 5m 30m 日K 周K; 写一个和股票网页一样的点击后有变色效果的整体
时间: 2024-04-09 09:28:49 浏览: 15
要实现点击按钮后整体变色的效果,你可以使用 Vue 的事件绑定和样式绑定来实现。首先,在你的 Vue 组件中,定义一个 data 属性来保存按钮的点击状态,例如:
```javascript
data() {
return {
activeButton: null
};
}
```
然后,在每个按钮上绑定点击事件,并在事件处理函数中更新 `activeButton` 的值,例如:
```html
<template>
<div>
<button :class="{ active: activeButton === '1m' }" @click="activeButton = '1m'">1m</button>
<button :class="{ active: activeButton === '5m' }" @click="activeButton = '5m'">5m</button>
<button :class="{ active: activeButton === '30m' }" @click="activeButton = '30m'">30m</button>
<button :class="{ active: activeButton === 'daily' }" @click="activeButton = 'daily'">日K</button>
<button :class="{ active: activeButton === 'weekly' }" @click="activeButton = 'weekly'">周K</button>
</div>
</template>
```
在上面的代码中,通过 `:class` 绑定语法来动态添加 `active` class,当 `activeButton` 的值与按钮的值相等时,按钮会应用这个样式。
最后,在你的样式表中定义 `.active` 类的样式,例如:
```css
.button-container button.active {
background-color: red;
color: white;
}
```
这样,当你点击按钮时,被点击的按钮会变成红色背景和白色字体,实现了整体变色的效果。
相关推荐
![text/x-java](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![html](https://img-home.csdnimg.cn/images/20210720083451.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/x-java](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)