4_v-bind.html 948 B

12345678910111213141516171819202122232425262728293031323334353637
  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. <script src="./js/vue.js"></script>
  8. <style>
  9. .active{
  10. font-size: 50px;
  11. font-weight: bold;
  12. color: red;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="app">
  18. <!-- 绑定属性 只要给一个属性加上v-bind 那么后面的值会被解析成变量 -->
  19. <img v-bind:src="imgSrc" alt="">
  20. <!-- <div v-bind:class="a"> hello world</div> -->
  21. <div v-bind:class="{'active':isActive}">hello world</div>
  22. <div :class="{'active':isActive}">hello world</div>
  23. </div>
  24. <script>
  25. new Vue({
  26. el:"#app",
  27. data:{
  28. imgSrc:"./img/logo.png",
  29. a:"active",
  30. isActive:true
  31. }
  32. })
  33. </script>
  34. </body>
  35. </html>