3_vbind.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. .div1{
  10. color: red;
  11. }
  12. .div2{
  13. color: blue;
  14. }
  15. .div3{
  16. font-size: 40px;
  17. color: green;
  18. }
  19. h1{
  20. display: none;
  21. }
  22. .active{
  23. display: block;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="app">
  29. <!-- v-bind 指令 可以将变量数据绑定到元素的属性上 -->
  30. <!-- 只要标签属性值为变量那么就可以在属性前面添加 v-bind: 前缀 -->
  31. <img v-bind:src="imgUrl2" alt="">
  32. <div v-bind:class="className">hello</div>
  33. <!-- 可以在指令中使用表达式 -->
  34. <div v-bind:class="className2+'3'">hello2</div>
  35. <!-- 可以在指令中使用条件表达式 -->
  36. <h1 v-bind:class="{'active':isShow}"> 你好 </h1>
  37. <!-- v-bind 可以缩写为 : -->
  38. <div :class="className">hello3</div>
  39. </div>
  40. <script>
  41. new Vue({
  42. el:"#app",
  43. data:{
  44. imgUrl:"./img/logo-mi2.png",
  45. imgUrl2:"./img/download.png",
  46. className:"div2",
  47. className2:"div",
  48. isShow:false,
  49. }
  50. })
  51. </script>
  52. </body>
  53. </html>