element中el-button点击多个同时高亮
时间: 2024-01-24 12:08:12 浏览: 164
你可以使用 `active` 属性来控制按钮是否高亮,然后通过 JavaScript 来实现点击多个按钮同时高亮的效果。
HTML 代码示例:
```
<el-button @click="toggleActive(1)" :active="activeButtons.includes(1)">Button 1</el-button>
<el-button @click="toggleActive(2)" :active="activeButtons.includes(2)">Button 2</el-button>
<el-button @click="toggleActive(3)" :active="activeButtons.includes(3)">Button 3</el-button>
```
JavaScript 代码示例:
```
data() {
return {
activeButtons: []
}
},
methods: {
toggleActive(buttonIndex) {
if (this.activeButtons.includes(buttonIndex)) {
// 如果该按钮已经被高亮,则取消高亮
this.activeButtons = this.activeButtons.filter(index => index !== buttonIndex)
} else {
// 如果该按钮没有被高亮,则添加高亮
this.activeButtons.push(buttonIndex)
}
}
}
```
这样,当你点击某个按钮时,它会切换高亮状态,并且如果同时有其他按钮被高亮,它们也会保持高亮状态。
阅读全文