<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.active{
color: red;
}
</style>
</head>
<body>
<!-- 可能会有需求,在不同的情况对某个标签进行不同的样式处理。
此时可以使用v-bind处理 -->
<div id="app">
<!-- <h2 class="active">{{message}}</h2> -->
<!-- <h2 :class='active'>{{message}}</h2> -->
<!-- <h2 v-bind:class="{样式类名1:boolean,样式类名2:boolean.....}"></h2> -->
<!-- 这还支持静态class和动态class动态合并 -->
<h2 class="title" :class="{active:isActive,line:isLine}">{{message}}</h2>
<h2 class="title" :class="getClasss()">{{message}}</h2>
<button @click="btnClick">切换</button>
</div>
<script src="../js/vue.js"></script>
<script>
const app=new Vue({
el:'#app',
data:{
message:'你好啊',
isActive:true,
isLine:true
},
methods:{
btnClick:function(){
this.isActive=!this.isActive
},
getClasss(){
return {active:this.isActive,line:this.isLine};
}
}
})
</script>
</body>
</html>
可结合检查(F12)的Elements和Console面板使用