<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Vue中多个元素或组件的过渡</title>
<script src="./vue.js"></script>
<style>
.v-enter, .v-leave-to {
opacity: 0;
}
.v-enter-active, .v-leave-active {
transition: opacity 1s;
}
</style>
</head>
<body>
<div id="root">
<transition mode="out-in">
<child v-if="show"></child>
<child-one v-else></child-one>
</transition>
<button @click="handleClick">切换</button>
</div>
<script>
Vue.component('child', {
template: '<div>child</div>'
})
Vue.component('child-one', {
template: '<div>child-one</div>'
})
new Vue({
el: "#root",
data: {
show: true
},
methods: {
handleClick: function() {
this.show = !this.show
},
}
})
</script>
</body>
</html>