transition.html 2.1 KB

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