Lottie · Vue

Lottie in Vue

Add Lottie animated icons to Vue 3 or Nuxt projects using the lottie-web library with the Composition API.

1

Install lottie-web

Add the lottie-web package from npm.

copy
npm install lottie-web
2

Add the animation to your component

Use a template ref for the container and initialise lottie-web inside onMounted.

copy
<template>
  <div ref="lottieContainer" style="width: 150px; height: 150px;"></div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import lottie from 'lottie-web'
import animationData from '@/assets/your_animation.json'

const lottieContainer = ref(null)

onMounted(() => {
  lottie.loadAnimation({
    container: lottieContainer.value,
    renderer: 'svg',
    loop: true,
    autoplay: true,
    animationData
  })
})
</script>
3

Control the animation

Store the animation instance returned by loadAnimation to control playback.

copy
const anim = lottie.loadAnimation({ ... })

anim.pause()
anim.play()
anim.stop()
Get your icons
Browse animated icons ready for Vue.
Browse free icons →