| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <script setup vapor>
- import { ref } from 'vue'
- import VdomComp from './components/VdomComp.vue'
- import MyTransitionGroup from './components/MyTransitionGroup.vue'
- const items = ref(['a', 'b', 'c'])
- const enterClick = () => items.value.push('d', 'e')
- const leaveClick = () => (items.value = ['b'])
- const enterLeaveClick = () => (items.value = ['b', 'c', 'd'])
- const appear = ref(false)
- window.setAppear = () => (appear.value = true)
- const moveClick = () => (items.value = ['d', 'b', 'a'])
- const name = ref('invalid')
- const dynamicClick = () => (items.value = ['b', 'c', 'a'])
- const changeName = () => {
- name.value = 'group'
- items.value = ['a', 'b', 'c']
- }
- let calls = []
- window.getCalls = () => {
- const ret = calls.slice()
- calls = []
- return ret
- }
- const eventsClick = () => (items.value = ['b', 'c', 'd'])
- const interopClick = () => (items.value = ['b', 'c', 'd'])
- </script>
- <template>
- <div class="transition-group-container">
- <div class="enter">
- <button @click="enterClick">enter button</button>
- <div>
- <transition-group name="test">
- <div v-for="item in items" :key="item" class="test">{{ item }}</div>
- </transition-group>
- </div>
- </div>
- <div class="leave">
- <button @click="leaveClick">leave button</button>
- <div>
- <transition-group name="test">
- <div v-for="item in items" :key="item" class="test">{{ item }}</div>
- </transition-group>
- </div>
- </div>
- <div class="enter-leave">
- <button @click="enterLeaveClick">enter-leave button</button>
- <div>
- <transition-group name="test">
- <div v-for="item in items" :key="item" class="test">{{ item }}</div>
- </transition-group>
- </div>
- </div>
- <div class="appear">
- <button @click="enterClick">appear button</button>
- <div v-if="appear">
- <transition-group
- appear
- appear-from-class="test-appear-from"
- appear-to-class="test-appear-to"
- appear-active-class="test-appear-active"
- name="test"
- >
- <div v-for="item in items" :key="item" class="test">{{ item }}</div>
- </transition-group>
- </div>
- </div>
- <div class="move">
- <button @click="moveClick">move button</button>
- <div>
- <transition-group name="group">
- <div v-for="item in items" :key="item" class="test">{{ item }}</div>
- </transition-group>
- </div>
- </div>
- <div class="dynamic-name">
- <button class="toggleBtn" @click="dynamicClick">dynamic button</button>
- <button class="changeNameBtn" @click="changeName">change name</button>
- <div>
- <transition-group :name="name">
- <div v-for="item in items" :key="item">{{ item }}</div>
- </transition-group>
- </div>
- </div>
- <div class="events">
- <button @click="eventsClick">events button</button>
- <div v-if="appear">
- <transition-group
- name="test"
- appear
- appear-from-class="test-appear-from"
- appear-to-class="test-appear-to"
- appear-active-class="test-appear-active"
- @beforeEnter="() => calls.push('beforeEnter')"
- @enter="() => calls.push('onEnter')"
- @afterEnter="() => calls.push('afterEnter')"
- @beforeLeave="() => calls.push('beforeLeave')"
- @leave="() => calls.push('onLeave')"
- @afterLeave="() => calls.push('afterLeave')"
- @beforeAppear="() => calls.push('beforeAppear')"
- @appear="() => calls.push('onAppear')"
- @afterAppear="() => calls.push('afterAppear')"
- >
- <div v-for="item in items" :key="item" class="test">{{ item }}</div>
- </transition-group>
- </div>
- </div>
- <div class="reusable-transition-group">
- <button @click="moveClick">reusable button</button>
- <div>
- <MyTransitionGroup name="group">
- <div v-for="item in items" :key="item" class="test">{{ item }}</div>
- </MyTransitionGroup>
- </div>
- </div>
- <div class="interop">
- <button @click="interopClick">interop button</button>
- <div>
- <transition-group name="test">
- <VdomComp v-for="item in items" :key="item">
- <div>{{ item }}</div>
- </VdomComp>
- </transition-group>
- </div>
- </div>
- </div>
- </template>
- <style>
- .transition-group-container > div {
- padding: 15px;
- border: 1px solid #f7f7f7;
- margin-top: 15px;
- }
- .test-move,
- .test-enter-active,
- .test-leave-active {
- transition: all 50ms cubic-bezier(0.55, 0, 0.1, 1);
- }
- .test-enter-from,
- .test-leave-to {
- opacity: 0;
- transform: scaleY(0.01) translate(30px, 0);
- }
- .test-leave-active {
- position: absolute;
- }
- </style>
|