10
0

7.样式绑定.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. .happy {
  9. width: 300px;
  10. height: 200px;
  11. background-color: red;
  12. margin: 100px auto;
  13. }
  14. .word {
  15. color: #ff0;
  16. font-size: 36px;
  17. font-weight: 600;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <!--
  23. 样式绑定内置指令:
  24. class 和 style
  25. 1.v-bind:class="样式"
  26. 2.:class="样式"
  27. -->
  28. <div id="app">
  29. <!-- 对象 -->
  30. <!-- <div :class="{happy:isShow,word:isShow}">你好</div> -->
  31. <!-- <div v-bind:class="{happy:isShow}"></div> -->
  32. <!-- <div v-bind:class="{happy:true}"></div> -->
  33. <!-- 数组 -->
  34. <!-- <div :class="['happy','word']">你好</div> -->
  35. <!-- <div v-bind:class="['happy','word']">你好</div> -->
  36. <!-- 数组 + 对象 -->
  37. <div :class="['happy',{word:true}]">哈哈哈哈</div>
  38. </div>
  39. <script src="./vue.js"></script>
  40. <script>
  41. var app = new Vue({
  42. el: "#app",
  43. data: {
  44. isShow: true,
  45. },
  46. });
  47. </script>
  48. </body>
  49. </html>