vue实现动态绑定class--(boolean)绑定class,点击有,再点击取消

<template>
  <div :class="{'flag':selected}" @click=clickBtn>xxx</div>
</template>
export default{
  data(){
    return{
      flag :false
    }
  },
  methods:{
    clickBtn(){
      this.flag = !this.flag
    }
  }
}
<style scoped>
.selected{
  color:red
}
<style>

猜你喜欢

转载自www.cnblogs.com/wd163/p/12114867.html
今日推荐