3_v-bind.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .box1{
  9. color: red;
  10. }
  11. .box2{
  12. color: blue;
  13. }
  14. .box3{
  15. font-size: 30px;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="app">
  21. <!-- v-bind: 可以将属性值解析成变量 -->
  22. <!-- 可以省略v-bind: 直接使用 : -->
  23. <!-- <div v-bind:class="className">hello world</div> -->
  24. <div :class="'active '+ className">hello world</div>
  25. <div v-bind:class="{'box1':isActive}">你好世界</div>
  26. <div v-bind:class="[className2,className]">你好世界</div>
  27. </div>
  28. <!-- v-bind 指令 功能类似于js中的setAttribute / getAttribute方法 可以向标签中动态绑定属性值 -->
  29. <script src="./js/vue.js"></script>
  30. <script>
  31. new Vue({
  32. el:"#app",
  33. data:{
  34. className:"box2",
  35. className2:"box3",
  36. isActive:false
  37. }
  38. })
  39. </script>
  40. </body>
  41. </html>