码迷,mamicode.com
首页 > 其他好文 > 详细

vue实现动态绑定class--多个按钮点击一个有一个

时间:2019-12-29 14:52:20      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:item   methods   eth   ret   cte   sele   ted   red   export   

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

vue实现动态绑定class--多个按钮点击一个有一个

标签:item   methods   eth   ret   cte   sele   ted   red   export   

原文地址:https://www.cnblogs.com/wd163/p/12114904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!