vue实现动态绑定class--(boolean)绑定class,点击有,再点击取消
<template>
//:class="{样式名:布尔值}"
<div :class="{selected:flag}" @click="clickBtn">点击改变颜色</div>
</template>
export default{
data(){
return{
flag :false
}
},
methods:{
clickBtn(){
this.flag = !this.flag
}
}
}
<style scoped>
.selected{
color: red
}
<style>