Animated hook function of Vue leave function

< div id= "app" >

    <fade :visible="visible">
        <div>16</div>
    </fade>
    <button @click="handleClick"></button>
</div>
<script>
    Vue.component("fade",{
        props:["visible"],
        template:`
            <transition
                :css="false"
                @before-enter="beforeEnter"
                @enter="enter"
                @before-leave="beforeLeave"
                @leave="leave"
            >
                <slot v-if="visible"></slot>
            </transition>
        `,
        methods:{
            beforeEnter(el){
                el.style.opacity=0
            },
            enter(el,done){
                el.offsetWidth;
                el.style.opacity=1;
                el.style.transition="opacity 2s ease .1s";
                done()
            },
            beforeLeave(el){
                el.style.opacity=1;    
            },
            leave(el,done){
                el.offsetWidth;
                el.style.opacity=0;
                el.style.transition="opacity 3s ease .1s";
                done()
                
            }
        }
    })
    var vm = new Vue({
        el:"-sharpapp",
        data:{
            visible:false,
        },
        methods:{
            handleClick(){
                this.visible=!this.visible
            }
        }

    })
</script>

want to write a click button div to achieve the transition to show and hide the effect. Use the hook function of vue"s animation, but why doesn"t the animation take effect?

Apr.23,2021

you call the done function, which means that the execution has been completed, and vue automatically removes the node, so there is no animation.


do you understand? In the same doubt, according to the upstairs statement, it is possible not to call done in leave, but without calling done, the page element actually exists after the animation ends, and has not been removed

.
Menu