对象语法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.active{
color: red;
}
</style>
</head>
<body>
<div id="app">
<h2 class="title" :class="{active: isActive, line:isLine}">{{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;
}
}
})
</script>
</body>
</html>