5.样式处理—style.html 905 B

123456789101112131415161718192021222324252627282930
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. <script src="../../vue.js"></script>
  9. </head>
  10. <body>
  11. <div id="app">
  12. <!-- 样式处理:内联样式的动态绑定 -->
  13. <!-- v-bind 指令 可以缩写为 “:”-->
  14. <!-- 动态绑定内联样式时,可以使用对象语法。对象的属性 就是 最终样式的属性 -->
  15. <p :style="{color, fontSize: fontSize + 'px', fontWeight: 700}">
  16. 对象语法
  17. </p>
  18. <p :style="[{color}, {fontSize: fontSize + 'px'}]">数组语法</p>
  19. </div>
  20. <script>
  21. var vm = new Vue({
  22. el: '#app',
  23. data: {
  24. color: 'red',
  25. fontSize: 20,
  26. },
  27. });
  28. </script>
  29. </body>
  30. </html>