【问题标题】:Transition not working properly on vue when div is being hiding隐藏div时,过渡在vue上无法正常工作
【发布时间】:2022-01-15 13:18:16
【问题描述】:

我有简单的转换来切换 div 文本,但是转换仅在隐藏文本时起作用,但是当我单击显示文本时,转换在这里不起作用,这是我的代码:

<template>
<div>
    <transition name="fade">
        <div v-if="this.showName">My name is Simon</div>
    </transition>
    <button @click="showName = !showName">Toggle</button>
</div>
</template>

<script>
export default {

    data(){
      return {
          showName: false,
      }
    },

    name: "StatusComponent"
}
</script>

<style scoped>
.fade-enter-from{
    opacity: 0;
}
.fade-enter-to{
    opacity: 1;
}
.fade-enter-active{
    transition: all 2s ease;
}
.fade-leave-from{
    opacity: 1;
}
.fade-leave-to{
    opacity: 0;
}
.fade-leave-active{
    transition: all 2s ease;
}
</style>

【问题讨论】:

    标签: vue.js vuejs2


    【解决方案1】:
    <div>
       <p  v-if="showName">My name is Simon</p>
    </div>
    

    你应该在div标签下打开一个p标签

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-29
      • 2020-06-06
      • 2014-11-29
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多