<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;
    }
  }
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/vue/2.7.8/vue.min.js