
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.active {
background-color: #009900;
color: white;
}
</style>
</head>
<body>
<div id="app">
<!-- 点击开时 flag=0 flag==0添加类active样式 -->
<!-- 点击关时 flag=1 flag==1添加类active样式 -->
<button type="button" @click="flag=0" :class="{'active':flag==0}">开</button>
<button type="button" @click="flag=1" :class="{'active':flag==1}">关</button><br>
<!-- 刚开始有styleObj样式,点击时就和当前样式相反,进行来回进行 -->
<button type="button" :class="styleObj" @click="styleObj.active=!styleObj.active">
<span v-if="styleObj.active">开</span>
<span v-else>关</span>
</button>
</div>
</body>