首页 > 语言 > JavaScript > 正文

Vue点击切换颜色的方法

2024-05-06 15:30:06
字体:
来源:转载
供稿:网友

如下所示:

<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点击切换颜色的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持错新站长站。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选