vue實現動態綁定class--多個按鈕點擊一個有一個


<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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM