| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Vue中的样式绑定</title>
- <script src="../vue.js"></script>
- <style>
- .activated {
- color: #f40808;
- }
- .activated-one {
- color: #000000;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <div
- @click="handleDivClick" :class="[activated]"
- >
- Hello world
- </div>
- <div :style="styleObj" @click="handleDivClick">
- China
- </div>
- </div>
- <script>
- var vm = new Vue({
- el: "#app",
- data: {
- activated: "",
- styleObj: {
- color: "black"
- }
- },
- methods: {
- handleDivClick: function (){
- this.activated = this.activated === "activated" ? "" : "activated"
- this.styleObj.color = this.styleObj.color === "black" ? "red":"black"
- }
- }
- })
- </script>
- </body>
- </html>
|