<!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 {
width: 100px;
height: 100px;
border: 1px solid red;
}
.error {
background-color: orange;
}
</style>
</head>
<body>
<div id="app">
<div v-bind:class="{active:isActive,error:isError}">
我是歌谣
</div>
<button v-on:click="handle">切换</button>
</div>
<script type="text/javascript" src="./js/vue.js"></script>
<script>
/* 样式绑定 */
var vm = new Vue({
//绑定的标签
el: '#app',
//自定义按键修饰符
data: {
isActive: true,
isError: true
},
methods: {
handle: function() {
//控制isactive奇幻
this.isActive = !this.isActive;
this.isError = !this.isError;
}
}
});
</script>
</body>
</html>