Vue3 changes the background color of the el-button selected [vue3 basics]

For example: change the background color of a selected el-button button
提示:选中某个按钮以后要求这个按钮是高亮的状态或者是其他背景颜色

For example:

Learning Content:

提示:这里用到了active,通过激活按钮来使其生效


Code steps:

提示:<el-button type="primary" v-for="(item, index) in xxxdata" :key="index" :class="{active: activeButtonIndex === index}" @click="changeClick(item, index)">xxx按钮</el-button>

For example:

  • First define activeButtonIndex as null
  • Set active style
  • The style rendering after selecting a button

Final Results:

提示:在点击按钮的时候 把index 传过去 ,把当前的index值赋值给activeButtonIndex。通过判断activeButtonIndex 是否等于 index 来决定按钮是否高亮显示。

Assignment such as: const changeClick = (item, index) => { activeButtonIndex.value = index }

Guess you like

Origin blog.csdn.net/weixin_48211022/article/details/131769092