v-for生成序列

<ul>
      <li v-for="(info,index) in list" :key="info.id" @click="select(index)" v-bind:class="{'active':info.active}">{{info.name}}</li>
</ul>

data数据

list:[
        {
          name:'a',
          id:1,
          active:false
        },
        {
          name:'b',
          id:2,
          active:false
        },
        {
          name:'c',
          id:3,
          active:false
        },
        {
          name:'d',
          id:4,
          active:false
        },
      ]

点击事件

select(d){
      this.list.map(s=>s.active=false);
      this.list[d].active=true;
    },

CSS样式

<style scoped>
li.active{
  background-color: red;
}

  v-for产生的列表,实现active的切换


 

返回目录

相关文章:

  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案