<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
<style>
h1 {
position: absolute;
}
@keyframes flyin {
0% {
transform: translateX(-200);
}
10% {
transform: translateX(0px);
}
}
@keyframes flyout {
0% {
transform: translateX(0px);
}
10% {
transform: translateX(-200px);
}
}
.transition {
transition: all 1s;
}
.v-enter-active {
animation: flyin 1s;
}
.v-leave-active {
animation: flyout 1s linear;
}
</style>
</head>
<body>
<div id="root"></div>
</body>
<script>
const app = Vue.createApp({
data() {
return {
isShow: true,
transition: true,
};
},
methods: {
handleClick() {
this.isShow = !this.isShow;
},
},
template: `
<transition>
<h1 v-if="isShow" >hello world</h1>
</transition>
<button v-on:click="handleClick">点击</button>
`,
});
const vm = app.mount("#root");
</script>
</html>