vue 点击动态设置li背景颜色


1.html

               <ul>
                  <li v-for='(item,index) in liList' :class='{actived:index==isactive}'
                  @click='clickLi(index)'>{{item}}</li>
                </ul>
 
2.
data() {
      return {
        isactive:0, //默认第一个有样式
        liList:['新增用户','退费用户','复购用户'],
      }
    },
 
methods:{
  
     // 用户点击切换
      clickLi(index){
        //点击切换 变量的值 赋值为 index
        this.isactive=index;
        console.log(index);
      }
 
}
3.
 
<style lang="scss" scoped>
  
 .actived{
    background-color: #2E75F2!important;
  }
</style>
 


免责声明!

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



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