当前位置:主页 > 网页前端 > vue >

Vue点击切换颜色的方法

时间:2020-12-03 17:56:49 | 栏目:vue | 点击:

如下所示:

<template>
 <div>
  <div v-for="(list,index) in siYuan" class="aa" :class="{ red:changeRed == index}" @click="change(index)">{{list.a}}</div>
 </div>
</template>
 
<script>
export default {
 data(){
  return{
   siYuan:[
    {"a":"田"},
    {"a":"心"},
    {"a":"水"},
    {"a":"原"}
   ],
   changeRed:-1
  }
 },
 methods:{
  change(index){
   this.changeRed = index;
  }
 }
 
}
</script>
 
<style>
 .aa{
  cursor: pointer;
 }
 .red{
  color: red;
 }
</style>

您可能感兴趣的文章:

相关文章