<div id="app">
<transition name="fade">
<div v-show="show">v-show</div>
</transition>
<transition name="fade">
<div v-if="show">v-if</div>
</transition>
<button @click="handleBtnClick">切换</button>
</div>
.fade-leave-to,
.fade-enter {
opacity: 0;
}
.fade-leave-active,
.fade-enter-active {
transition: opacity 1s;
}
var app = new Vue({
el: "#app",
data: {
show: true
},
methods: {
handleBtnClick: function () {
this.show = !this.show;
}
}
});
This Pen doesn't use any external CSS resources.