Vue Directive 自定义属性

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
<template>
<div class="box" v-animation>
BOX
</div>
</template>

<style>
@keyframes move {
0% {
transform: translateX(0px);
}

50% {
transform: translateX(100px);
}

1000% {
transform: translateX(0px);
}
}

.box {
box-sizing: border-box;
width: 100px;
height: 100px;
background-color: aquamarine;
display: flex;
justify-content: center;
align-items: center;
}

.animation {
transition: 1s ease;
animation: move 1s infinite;
}
</style>
<script setup>
const vAnimation = {
mounted: (el) => {
el.classList.add('animation')
}
}
</script>

初始化之后,Box开始左右摇摆。