<!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>
.transition {
transition: all 1s linear;
}
.v-enter-from {
opacity: 0;
}
.v-enter-from {
opacity: 1;
}
.v-enter-active {
transition: opacity 1s linear;
}
.v-leave-from {
opacity: 1;
}
.v-leave-to {
opacity: 0;
}
.v-leave-active {
transition: opacity 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>