Install lottie-web, grab a ref to a container div, and load the animation in onMounted. Works the same in Vue 3 and Nuxt.
Add the package from npm.
npm install lottie-webUse a template ref for the container. onMounted is the right place — Lottie needs the actual DOM element.
<template>
<div ref="lottieContainer" style="width: 150px; height: 150px;"></div>
</template>
<script setup>
import { onMounted, onUnmounted, ref } from 'vue'
import lottie from 'lottie-web'
import animationData from '@/assets/your_animation.json'
const lottieContainer = ref(null)
let anim = null
onMounted(() => {
anim = lottie.loadAnimation({
container: lottieContainer.value,
renderer: 'svg',
loop: true,
autoplay: true,
animationData
})
})
onUnmounted(() => anim?.destroy())
</script>The instance returned by loadAnimation has pause, play, and stop methods you can call from anywhere in the component.
anim.pause()
anim.play()
anim.stop()Does this work in Nuxt?
Yes. The onMounted pattern keeps Lottie browser-only, so it won't run during SSR and won't cause hydration issues.
Should I use lottie-web or a Vue package?
lottie-web directly. Vue-specific wrappers add complexity without much benefit — the vanilla API is simple enough with a ref and onMounted.
How do I clean up when the component unmounts?
Call anim.destroy() in onUnmounted. The code above already shows this pattern.
Get your animated icons
Browse icons ready for Vue — free to download.