App.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <script setup vapor>
  2. import { ref } from 'vue'
  3. import VdomComp from './components/VdomComp.vue'
  4. const items = ref(['a', 'b', 'c'])
  5. const enterClick = () => items.value.push('d', 'e')
  6. const leaveClick = () => (items.value = ['b'])
  7. const enterLeaveClick = () => (items.value = ['b', 'c', 'd'])
  8. const appear = ref(false)
  9. window.setAppear = () => (appear.value = true)
  10. const moveClick = () => (items.value = ['d', 'b', 'a'])
  11. const name = ref('invalid')
  12. const dynamicClick = () => (items.value = ['b', 'c', 'a'])
  13. const changeName = () => {
  14. name.value = 'group'
  15. items.value = ['a', 'b', 'c']
  16. }
  17. let calls = []
  18. window.getCalls = () => {
  19. const ret = calls.slice()
  20. calls = []
  21. return ret
  22. }
  23. const eventsClick = () => (items.value = ['b', 'c', 'd'])
  24. const interopClick = () => (items.value = ['b', 'c', 'd'])
  25. </script>
  26. <template>
  27. <div class="transition-group-container">
  28. <div class="enter">
  29. <button @click="enterClick">enter button</button>
  30. <div>
  31. <transition-group name="test">
  32. <div v-for="item in items" :key="item" class="test">{{ item }}</div>
  33. </transition-group>
  34. </div>
  35. </div>
  36. <div class="leave">
  37. <button @click="leaveClick">leave button</button>
  38. <div>
  39. <transition-group name="test">
  40. <div v-for="item in items" :key="item" class="test">{{ item }}</div>
  41. </transition-group>
  42. </div>
  43. </div>
  44. <div class="enter-leave">
  45. <button @click="enterLeaveClick">enter-leave button</button>
  46. <div>
  47. <transition-group name="test">
  48. <div v-for="item in items" :key="item" class="test">{{ item }}</div>
  49. </transition-group>
  50. </div>
  51. </div>
  52. <div class="appear">
  53. <button @click="enterClick">appear button</button>
  54. <div v-if="appear">
  55. <transition-group
  56. appear
  57. appear-from-class="test-appear-from"
  58. appear-to-class="test-appear-to"
  59. appear-active-class="test-appear-active"
  60. name="test"
  61. >
  62. <div v-for="item in items" :key="item" class="test">{{ item }}</div>
  63. </transition-group>
  64. </div>
  65. </div>
  66. <div class="move">
  67. <button @click="moveClick">move button</button>
  68. <div>
  69. <transition-group name="group">
  70. <div v-for="item in items" :key="item" class="test">{{ item }}</div>
  71. </transition-group>
  72. </div>
  73. </div>
  74. <div class="dynamic-name">
  75. <button class="toggleBtn" @click="dynamicClick">dynamic button</button>
  76. <button class="changeNameBtn" @click="changeName">change name</button>
  77. <div>
  78. <transition-group :name="name">
  79. <div v-for="item in items" :key="item">{{ item }}</div>
  80. </transition-group>
  81. </div>
  82. </div>
  83. <div class="events">
  84. <button @click="eventsClick">events button</button>
  85. <div v-if="appear">
  86. <transition-group
  87. name="test"
  88. appear
  89. appear-from-class="test-appear-from"
  90. appear-to-class="test-appear-to"
  91. appear-active-class="test-appear-active"
  92. @beforeEnter="() => calls.push('beforeEnter')"
  93. @enter="() => calls.push('onEnter')"
  94. @afterEnter="() => calls.push('afterEnter')"
  95. @beforeLeave="() => calls.push('beforeLeave')"
  96. @leave="() => calls.push('onLeave')"
  97. @afterLeave="() => calls.push('afterLeave')"
  98. @beforeAppear="() => calls.push('beforeAppear')"
  99. @appear="() => calls.push('onAppear')"
  100. @afterAppear="() => calls.push('afterAppear')"
  101. >
  102. <div v-for="item in items" :key="item" class="test">{{ item }}</div>
  103. </transition-group>
  104. </div>
  105. </div>
  106. <div class="interop">
  107. <button @click="interopClick">interop button</button>
  108. <div>
  109. <transition-group name="test">
  110. <VdomComp v-for="item in items" :key="item">
  111. <div>{{ item }}</div>
  112. </VdomComp>
  113. </transition-group>
  114. </div>
  115. </div>
  116. </div>
  117. </template>
  118. <style>
  119. .transition-group-container > div {
  120. padding: 15px;
  121. border: 1px solid #f7f7f7;
  122. margin-top: 15px;
  123. }
  124. .test-move,
  125. .test-enter-active,
  126. .test-leave-active {
  127. transition: all 50ms cubic-bezier(0.55, 0, 0.1, 1);
  128. }
  129. .test-enter-from,
  130. .test-leave-to {
  131. opacity: 0;
  132. transform: scaleY(0.01) translate(30px, 0);
  133. }
  134. .test-leave-active {
  135. position: absolute;
  136. }
  137. </style>