1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <script src="./js/vue.js"></script>
- <style>
- .box1{
- color: red;
- }
- .box2{
- color: blue;
- }
- .active{
- font-size: 40px;
- font-weight: bolder;
- color: green;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <!-- 默认情况下在vue中标签上属性的值不能使用变量 -->
- <!-- 如果需要使用变量那么需要在属性前方加上v-bind 来声明属性使用的是变量 -->
-
- <div v-bind:class="styleName">hello</div>
- <button @click="changeClass('box1')">box1</button>
- <button @click="changeClass('box2')">box2</button>
- <!-- <img v-bind:src="imgSrc" alt=""> -->
- <!-- <img v-bind:src="imgSrc + '.jpg'" alt=""> -->
- <div v-bind:class="{ active : isActive }">你好</div>
- <div :style="{ fontSize:fontS+'px' }"> 世界 </div>
- </div>
- <script>
- var app = new Vue({
- el:"#app",
- data:{
- styleName:"",
- imgSrc:"./img/1",
- isActive:false,
- fontS:60
- },
- methods: {
- changeClass: function (cName) {
- this.styleName = cName;
- }
- },
- })
- </script>
- </body>
- </html>
|