App.vue 4.6 KB

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