效果图
![](https://img-blog.csdnimg.cn/f29ff92d564744b4acc20703ec50bf1e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Li06KGX55qE5bCP5a2p,size_20,color_FFFFFF,t_70,g_se,x_16)
代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 改变颜色</title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div id="app">
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">{{message}}</div>
<button @click="reverseColor1">红色</button>
<button v-on:click="reverseColor2">绿色</button>
<button v-on:click="reverseColor3">蓝色</button>
</div>
<script>
new Vue({
el: '#app',
data: {
message:'你好',
activeColor: 'green',
fontSize: 30,
},
methods:{
reverseColor1: function () {
this.activeColor='red'
},
reverseColor2: function () {
this.activeColor='green'
},
reverseColor3: function () {
this.activeColor='blue'
}
}
})
</script>
</body>
</html>