<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<style>
.btncolor{
background: red
}
</style>
</head>
<body>
<div id="app">
<!-- `greet` 是在下面定义的方法名 -->
<button id="btn" class="btncolor" :style="classObject" v-on:click="greet">Greet</button>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
classObject: {
background:''
}
},
// 在 `methods` 对象中定义方法
methods: {
greet: function (event) {
alert(1111)
if(this.classObject.background!='#ffffff')
this.classObject.background='#ffffff';
else {
this.classObject.background='#000000';
}
alert(222222);
}
}
})
</script>
</body>
</html>