您的位置:首页 > Web前端 > Vue.js

Vue点击切换颜色的方法

2018-09-13 10:03 836 查看

如下所示:

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

以上这篇Vue点击切换颜色的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Vue 切换 颜色