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