vue点击更改背景颜色


<template>
  <div>
    <div
      v-for="(item, index) in nameoptions"
      :class="{ active: index == isActive }"
      @click="checkItem(index)"
      :key="item.name"
    >
      {{ item.name }}
    </div>
  </div>
</template>
 
<script>
export default {
  name: "",
  data() {
    return {
      isActive: 0,
      nameoptions: [
        {
          name: "1",
        },
        {
          name: "2",
        },
        {
          name: "3",
        },
        {
          name: "4",
        },
      ],
    };
  },
  methods: {
    checkItem(index) {
      // console.log(index);
      this.isActive = index;
    },
  },
};
</script>
 
<style>
.active {
  background-color: blue;
  color: #fff;
}
</style>

来源:https://blog.csdn.net/weixin_47384925/article/details/119783229


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM