ブログの投稿ログ

2021年
9月
8月
7月
6月

transitionタグの使い方

でも

<template>
  <div class="hoge">
    <p><button v-on:click="show = !show">切り替え</button></p>
    <transition>
      <div v-if="show" key="a">TRUE</div>
      <div v-else key="b">FALSE</div>
    </transition>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      show: true,
    };
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.hoge {
  width: 70px;
  margin: auto;
  text-align: center;
}
.hoge div {
  display: inline;
}
.v-enter-active,
.v-leave-active {
  transition: opacity 1s;
}
.v-leave-active {
  position: absolute;
}
.v-enter,
.v-leave-to {
  opacity: 0;
}
</style>