基于Vue实现active点击切换样式

朱雀 2023-06-14 04:17 215阅读 0赞
  1. html

  2. 在循环的代码那里添加

    :class=”{‘active’: currentSort==index}”

  3. 添加样式

    .active {

    1. color: #009eef;

    }

  4. 初始化数据

    data() {

    1. return {
    2. currentSort:0,
    3. }

    },

  5. 调用方法

    methods: {

    1. active(index) {
    2. this.currentSort = index;
    3. }

    },

当我们触发点击事件的时候,传入循环的index ,这样我们就可以将绑定的样式赋给点击到的index

发表评论

表情:
评论列表 (有 0 条评论,215人围观)

还没有评论,来说两句吧...

相关阅读