7.样式绑定.html 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. .colors {
  9. color: red;
  10. }
  11. .aa {
  12. font-style: italic;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="app">
  18. <!--
  19. 内置指令:
  20. v-bind => :
  21. v-bind:class / :class
  22. -->
  23. <!-- 对象 -->
  24. <h1 v-bind:class="{colors:isShow}">{{msg}}</h1>
  25. <!-- 数组 -->
  26. <h1 v-bind:class="['colors','aa']">哈哈哈哈</h1>
  27. <!-- 数组 + 对象 -->
  28. <h1 :class="['colors',{aa: isShow}]">嘿嘿</h1>
  29. </div>
  30. <script src="./vue.js"></script>
  31. <!--
  32. -->
  33. <script>
  34. var app = new Vue({
  35. el:"#app",
  36. data:{
  37. msg:"你好啊",
  38. isShow: true
  39. }
  40. })
  41. </script>
  42. </body>
  43. </html>