代码之家  ›  专栏  ›  技术社区  ›  Jam3sn

子组件上的转换

  •  0
  • Jam3sn  · 技术社区  · 7 年前

    我正在建立一个基本的SPA,在页面之间转换。页面之间的转换工作正常,但是子组件不运行它们的转换。

    index.vue:

    <template>
      <main class="animated">
        <text-content :content="content"></text-content>
      </main>
    </template>
    
    <script>
    import TextContent from '~/components/TextContent.vue'
    
    export default {
      transition: {
        enterActiveClass: 'animated fadeIn',
        leaveActiveClass: 'animated fadeOut'
      },
    
      components: {
        TextContent
      },
    
    
      data() {
        return {
          content: {
            title: 'Title',
            body: '<p>Content</p>'
          }
        }
      }
    }
    </script>
    

    然后是我的子组件textcontent.vue:

    <template>
        <section class="container mx-auto my-14">
            <h1 class="mb-8">{{ content.title }}</h1>
    
            <div v-html="content.body">{{ content.body }}</div>
        </section>
    </template>
    
    <script>
    export default {
      transition: {
        enterActiveClass: 'animated fadeInUp',
        leaveActiveClass: 'animated fadeOutDown'
      },
    
      props: ['content']
    }
    </script>
    

    所以页面fadein-fadeout工作得很好,但是文本组件fadeinup-fadeout不起作用。

    我哪里出问题了?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Max Sinev    7 年前

    transition 属性仅与组件的路由转换相关,请使用 <transition> 在模板中标记并使用 appear 要在初始渲染时运行转换,请执行以下操作:

    <template>
      <main class="animated">
       <transition  
             appear-active-class="animated fadeInUp"
             appear>
          <text-content :content="content"></text-content>
       <transition>
      </main>
    </template>
    
    推荐文章