vue 对css样式进行修改
一、定义样式
<style> .blueBack { background-color: blue; } .yellowBack { background-color: yellow; } </style>
二、定义两个按钮,一个div
<div id="vueFirst"> <div :class="backColor">{{info}}</div> <hr> <input type="button" value="变黄" @click="changeColorToYellow"></input> <input type="button" value="变蓝" @click="changeColorToBlue"></input> </div>
三、添加click事件
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript"> var vm = new Vue({ el: "#vueFirst", data: { info: "hello world", backColor: "blueBack" }, methods: { changeColorToYellow() { this.backColor = "yellowBack" }, changeColorToBlue() { this.backColor = "blueBack" } } })
完整代码如下:
<html> <head> <style> .blueBack { background-color: blue; } .yellowBack { background-color: yellow; } </style> </head> <body> <div id="vueFirst"> <div :class="backColor">{{info}}</div> <hr> <input type="button" value="变黄" @click="changeColorToYellow"></input> <input type="button" value="变蓝" @click="changeColorToBlue"></input> </div> <script type="text/javascript" src="js/vue.js"></script> <script type="text/javascript"> var vm = new Vue({ el: "#vueFirst", data: { info: "hello world", backColor: "blueBack" }, methods: { changeColorToYellow() { this.backColor = "yellowBack" }, changeColorToBlue() { this.backColor = "blueBack" } } }) </script> </body> </html>
相关推荐
yuzhu 2020-11-16
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
sjcheck 2020-11-03
怪我瞎 2020-10-28
源码zanqunet 2020-10-28
gloria0 2020-10-26
王军强 2020-10-21
学习web前端 2020-09-28
QiaoranC 2020-09-25
anchongnanzi 2020-09-21
安卓猴 2020-09-12
Macuroon 2020-09-11
kiven 2020-09-11
LittleCoder 2020-09-11
Cheetahcubs 2020-09-13
小焊猪web前端 2020-09-10
颤抖吧腿子 2020-09-04
softwear 2020-08-21