<template>
//v-for循環出來多個按鈕,便於獲取index
<span v-for="(item,index) in list" :key="index" @click="countAuth(index)" :class="{selected:index==current}">
</span>
</template>
export default{
data(){
return{
list:["第一個按鈕","第二個按鈕","第三個按鈕","第四個按鈕"],
current:0 //自定義屬性,便於傳遞index
}
},
methods:{
countAuth(index){
this.current=index //傳遞
}
}
}
<style scoped>
selected{
color:red
}
<style>