美文网首页
v-bind和v-for结合使用动态绑定class

v-bind和v-for结合使用动态绑定class

作者: 秋分落叶 | 来源:发表于2019-11-01 15:02 被阅读0次
<template>
  <div>
    <ul>
      <li
        v-for="(item,index) in msgData"
        :key="index"
        @click="click(index)"
        :class="{active:select==index}"
      >{{item}}</li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      select: Int8Array,
      msgData: ["海尔", "葫芦娃", "蜘蛛侠", "我是谁"]
    };
  },
  methods: {
    click(index) {
      this.select = index;
      // alert(index)
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.active {
  color: red;
}
</style>

相关文章

网友评论

      本文标题:v-bind和v-for结合使用动态绑定class

      本文链接:https://www.haomeiwen.com/subject/iqnfbctx.html