Presence
Manages mounting and unmounting of element with transition support.
The difference between this component from Vue Transition is it accepts css animation, and control the visibility of element.
Presence component provides enhanced control over element mounting/unmounting. It ensures animations and transitions complete before removing elements from the DOM, making it perfect for animated UI components.
API Reference
| Prop | Default | Type |
|---|---|---|
present* | booleanConditional to mount or unmount the child element. Similar to | |
forceMount | booleanForce the element to render all the time.\n\nUseful for programmatically render grandchild component with the exposed |
| Event | Type |
|---|---|
enter | CustomEventEvent handler called when the enter animation has started |
after-enter | CustomEventEvent handler called when the enter animation has finished |
leave | CustomEventEvent handler called when the leave animation has started |
after-leave | CustomEventEvent handler called when the leave animation has finished |
Read our Animation Guide to learn more about implementing animations with Presence component.
Example
<template>
<APresence :present="isVisible">
<div
:data-state="isVisible ? 'open' : 'closed'"
class="data-[state=open]:animate-fadeIn data-[state=closed]:animate-fadeOut"
>
<slot />
</div>
</APresence>
</template>
Force Mount
When you need to ensure content is always rendered regardless of the present state:
<template>
<APresence
v-slot="{ present }"
:present="isVisible"
:force-mount="true"
>
<div>
This content will always be rendered
<div v-if="present">
This content is hidden
</div>
</div>
</APresence>
</template>