-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components transition enter
function not called when using Vue version 2.6.10
#10227
Comments
You need to use the appear prop for the animation to play initially |
I didn't say anything about initial render is an issue- if you press the toggle button multiple times, the enter function of |
I have the same problem, and i down to 2.6.8 to get work. |
the transition inside <transition :css="false" @enter="enter" @leave="leave" appear>
<div class="hello"> For the leave transition it's currently not possible, you can track the feature at #9328 I hope this helps :) |
Wait? Doesn't this also mean the HelloWorld component would animate / call the enter function on first load? I understand that this is the purpose of the And the leave transition isn't the issue here. It works as expected. Before the component dismounts, its I'm wondering why this change was introduced. We clearly lose functionality here. |
@posva could you please look into this again? I'm still under the impression there is a misunderstanding here. Again: I still do not understand why the enter function should be called in this situation // App.vue
<transition @enter="enter" @leave="leave" :css="false">
<img alt="Vue logo" src="./assets/logo.png" v-if="show">
</transition>
<HelloWorld msg="Helloooo" /> but not here // HelloWorld.vue
<transition :css="false" @enter="enter" @leave="leave">
<div class="hello">
<h1>{{ msg }}</h1>
....
</div>
</transition> It's hard to believe that this is intended. |
It is intended because the first one is wrapping an element with a v-if while the second isn't and it's directly there when the parent renders. So if you want it to apply the enter transition, you need the |
Okay, if I add But it also gets called on initial load of the app, which is not what I want and what I understand is exactly what I read what you are saying, but still not fully understand what you are trying to solve with this new implementation. What was wrong with the way it worked before? Maybe an example would help illustrating the problem the old implementation caused. |
The way it works now it the way it was always intended to work. Bug Report: #9628
That could only be the case if the So I assume it is (or can be) true at the initial load of your real app?
I would handle this in a global fashion, i.e. set a (non-reactive) flag in the main component to Then each component can check that flag on re-render and determine wether or not in provide() {
return {
isFirstRender: () => { return this.isFirstRender === false }
}
},
updated() {
this.isFirstRender = false // do *not* add this prop to `data`!
} in <template>
<transition
:appear="!isFirstRender()"
:css="false"
@enter="enter"
@leave="leave"
>
<div class="hello">
xxx
</div>
</transition>
</template>
<script>
import Vue from 'vue'
import { TweenMax } from 'gsap'
export default Vue.extend({
name: 'HelloWorld',
props: {
msg: String,
},
inject: ['isFirstRender'],
methods: {
enter(el, done) {
console.log('enter hello world called', el)
TweenMax.from(el, 2, { opacity: 0, xPercent: -100, onComplete: done })
},
leave(el, done) {
console.log('leave hello world called', el)
TweenMax.to(el, 2, { opacity: 0, xPercent: -100, onComplete: done })
},
},
})
</script> I used provide/inject so this can be re-used in all of the app in different places that need this. Other patterns, i.e. with HelloWorld accepting a prop, are also possible to imagine. |
@LinusBorg I think I found a slight thought error in your code. So if I'm correct the pattern should look like this: provide() {
return {
isFirstRender: () => { return this.isFirstRender === undefined }
}
},
updated() {
this.isFirstRender = false // do *not* add this prop to `data`!
} Atleast that's how it worked for me; now [EDIT] Here's what I don't understand: [EDIT 2] |
Version
2.6.10
Reproduction link
https://github.com/katerlouis/vue-2610-bug
Steps to reproduce
serve or build the app
and press the toggle button
What is expected?
HelloWorld component should call
enter
functionWhat is actually happening?
HelloWorld component doesn't call
enter
functionenter
of the transition directly insideApp.vue
(the logo img) gets called though, which is odd.With vue v2.5.17 it works as expected (haven't used any other vue version since)
The text was updated successfully, but these errors were encountered: