-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApp.vue
55 lines (46 loc) · 1.13 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script setup>
import { reactive, ref } from "vue";
const isShow = ref(true);
const items = reactive([1, 2, 3, 4, 5, 6, 7]);
const addRandom = () => {
const randomNumber = Math.floor(Math.random() * 10 + 1);
items.push(randomNumber);
};
const removeRandom = () => {
const randomIndex = Math.floor(Math.random() * items.length);
items.value = items.splice(randomIndex, 1);
};
</script>
<template>
<div>
<h1>Transition</h1>
<button @click="isShow = !isShow">Toggle fade</button>
<Transition name="fade">
<p v-show="isShow">Hello</p>
</Transition>
<button @click="addRandom">Add random number</button>
<button @click="removeRandom">Remove random number</button>
<TransitionGroup name="list" tag="ul">
<li v-for="item in items" :key="item">{{ item }}</li>
</TransitionGroup>
</div>
</template>
<style lang="css">
.fade-enter-active,
.fade-leave-active {
transition: opacity 3s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.list-enter-active,
.list-leave-active {
transition: all 0.5s ease;
}
.list-enter-from,
.list-leave-to {
opacity: 0;
transform: translateX(30px);
}
</style>