0
点赞
收藏
分享

微信扫一扫

vue 点击按钮改变颜色

郝春妮 2022-02-28 阅读 176

 效果图

代码

<!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>
举报

相关推荐

0 条评论