动态属性绑定 v-bind.html 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. <!-- 引入Vue 3 CDN -->
  8. <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  9. <style>
  10. .textColor {
  11. color: blue; /* 或者任何你想要的颜色 */
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div id="app">
  17. <!-- :value -->
  18. <h3>Value="baidu.com"</h3>
  19. <input type="text" :value="web.url">
  20. <h3>v-bind:Value="baidu.com"</h3>
  21. <input type="text" v-bind:value="web.url">
  22. <h3>:Value="baidu.com"</h3>
  23. <input type="text" :value="web.url">
  24. <!-- :src -->
  25. <h3>src="web.jpg":</h3>
  26. <img src="123.jpg">
  27. <h3>:src="web.img":</h3>
  28. <img :src="web.img">
  29. <!-- :class -->
  30. <h3>class="textColor"</h3>
  31. <b class="textColor">邓瑞编程</b>
  32. <h3>:class="'textColor': web.fontstatus"</h3>
  33. <b :class="{'textColor': web.fontstatus}">邓瑞编程</b>
  34. </div>
  35. <script>
  36. const { createApp, reactive } = Vue;
  37. createApp({
  38. setup() {
  39. // 定义响应式数据
  40. const web = reactive({
  41. url: "www.baidu.com",
  42. img: "123.jpg",
  43. fontstatus: true
  44. });
  45. return {
  46. web,
  47. };
  48. }
  49. }).mount('#app'); // 挂载到DOM元素上
  50. </script>
  51. </body>
  52. </html>