<div id="app">
<!-- :class="{ "class名称" : true / false }" -->
<div class="radio" :class="{ 'radio-selected' : radioSelected }"></div>
<hr />
<button @click="changeRadio()">{{radioSelected?'反选':'选中'}}</button>
</div>
<script>
var app = new Vue({
el:'#app',
data:{
// 是否添加 radio-selected 样式
radioSelected:false
},
methods:{
// 改变 radioSelected 的值
changeRadio:function() {
this.radioSelected = !this.radioSelected;
}
}
})
</script>
.radio {
width: 32px;
height: 32px;
border-radius: 50%;
border: 1px solid #777;
}
/* 用于动态添加的类 */
.radio-selected {
background: red;
}