transition.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <script src="../../../dist/vue.js"></script>
  7. <style type="text/css">
  8. .test {
  9. width: 600px;
  10. height: 100px;
  11. background-color: #f00;
  12. padding: 10px;
  13. border: 1px solid #000;
  14. overflow: hidden;
  15. transition: all .2s ease;
  16. -moz-transition: all .2s ease;
  17. -webkit-transition: all .2s ease;
  18. }
  19. .v-enter, .v-leave {
  20. height: 0;
  21. padding-top: 0;
  22. padding-bottom: 0;
  23. border-top-width: 0;
  24. border-bottom-width: 0;
  25. }
  26. .v-enter {
  27. background-color: #00f;
  28. }
  29. .v-leave {
  30. background-color: #0f0;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div id="test">
  36. <div>
  37. <button class="button-0" v-on="click:set">0</button>
  38. <button class="button-1" v-on="click:set">1</button>
  39. <button class="button-2" v-on="click:set">2</button>
  40. <button class="push" v-on="click:push">push</button>
  41. <button class="pop" v-on="click:pop">pop</button>
  42. <button class="splice" v-on="click:splice">splice</button>
  43. </div>
  44. <div
  45. class="test"
  46. v-repeat="item:items"
  47. v-if="filter(item)"
  48. v-transition
  49. v-attr="data-id:item.a">
  50. {{item.a}}
  51. </div>
  52. <div
  53. class="test"
  54. v-repeat="item:items"
  55. v-show="filter(item)"
  56. v-transition
  57. v-attr="data-id:item.a">
  58. {{item.a}}
  59. </div>
  60. </div>
  61. <h1 style="margin:0">123</h1>
  62. <script>
  63. var test = new Vue({
  64. el: '#test',
  65. scope: {
  66. b: 1,
  67. set: function (e) {
  68. this.b = +e.el.textContent
  69. },
  70. push: function () {
  71. this.items.push({a: this.items.length + 1 })
  72. },
  73. pop: function () {
  74. this.items.pop()
  75. },
  76. splice: function () {
  77. this.items.splice(0, 1, {a:99})
  78. },
  79. filter: function (item) {
  80. return item.a > this.b
  81. },
  82. items: [
  83. {
  84. a: 1
  85. },
  86. {
  87. a: 2
  88. }
  89. ]
  90. }
  91. })
  92. </script>
  93. </body>
  94. </html>