3_v-bind.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. <style>
  9. #orange {
  10. width: 200px;
  11. height: 200px;
  12. background: orange;
  13. }
  14. #red {
  15. width: 100px;
  16. height: 100px;
  17. background: red;
  18. }
  19. .aa {
  20. width: 200px;
  21. height: 200px;
  22. background: aqua;
  23. }
  24. .bb {
  25. color: red;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div id="app">
  31. <button @click="change">change</button>
  32. <!-- v-bind 动态绑定属性 -->
  33. <div v-bind:id="myName"></div>
  34. <!-- <div v-bind:id="color"></div> -->
  35. <div :id="color"></div>
  36. <div :class="{aa:isA,bb:isB}">1111</div>
  37. <div :class="[flag?class1:'',class2]">222</div>
  38. <!-- <div style="width: 300px;height: 300px;background: #000;"></div> -->
  39. <div :style="{color: color1}" :class="class1">333</div>
  40. <div :style="[s1,s2]">xixixixxixixii</div>
  41. </div>
  42. <script src="vue.js"></script>
  43. <script>
  44. var app = new Vue({
  45. el: '#app',
  46. data: {
  47. myName: 'zs',
  48. color: 'orange',
  49. isA: true,
  50. isB: true,
  51. flag: true,
  52. class1: 'aa',
  53. class2: 'bb',
  54. color1: 'green',
  55. s1: {
  56. width: '100px',
  57. height: '100px',
  58. background: 'black'
  59. },
  60. s2: {
  61. color: 'red'
  62. }
  63. },
  64. methods: {
  65. change() {
  66. this.myName = 'lisi'
  67. this.color = 'red'
  68. }
  69. }
  70. })
  71. </script>
  72. </body>
  73. </html>