dotLottie Vue Player Advanced Usage
Explore advanced usage patterns for the dotLottie Vue player, including direct control via refs and multi-animation support.
Vue Player Advanced Usage
This guide covers advanced patterns for the Vue player, including direct instance control via template refs and multi-animation support.
Advanced Animation Control
Using Refs for Direct Control
Access the underlying player instance via a template ref for programmatic control using its methods.
<template>
<DotLottieVue ref="player" src="path/to/animation.lottie" />
</template>
<script>
import { DotLottieVue } from "@lottiefiles/dotlottie-vue";
import { ref, onMounted, onUnmounted } from "vue";
export default {
components: {
DotLottieVue,
},
setup() {
const player = ref(null);
onMounted(() => {
// Access the player instance directly via the ref
// Note: The Vue component directly exposes core player methods.
const playerInstance = player.value;
if (!playerInstance) return;
// Example: Use documented methods available on the instance
playerInstance.setSpeed(2);
playerInstance.setSegment([10, 50]);
});
onUnmounted(() => {
// Clean up on unmount using documented destroy method
// accessed via the ref
player.value?.destroy();
});
return {
player,
};
},
};
</script>Multi-Animation Support
Switching Between Animations
Dynamically change the :src prop to load different animations.
<template>
<div>
<!-- Use :key binding to force re-render when src changes -->
<DotLottieVue
ref="player"
:key="currentAnimation"
:src="animations[currentAnimation]"
:autoplay="true"
:loop="true"
/>
<div class="animation-buttons">
<button
v-for="(_, id) in animations"
:key="id"
@click="switchAnimation(id)"
:class="{ active: currentAnimation === id }"
>
{{ id }}
</button>
</div>
</div>
</template>
<script>
import { DotLottieVue } from "@lottiefiles/dotlottie-vue";
import { ref } from "vue";
export default {
components: {
DotLottieVue,
},
setup() {
const player = ref(null);
const currentAnimation = ref("animation1");
const animations = {
animation1: "path/to/animation1.lottie",
animation2: "path/to/animation2.lottie",
animation3: "path/to/animation3.lottie",
};
const switchAnimation = (animationId) => {
currentAnimation.value = animationId;
};
return {
player,
currentAnimation,
animations,
switchAnimation,
};
},
};
</script>Next Steps
Explore Examples for more advanced use cases
Check out the complete Props Reference
Learn about Basic Usage
Last updated: May 5, 2026 at 5:55 AMEdit this page