Lottie Animations for Vue 3

3.3.1 · active · verified Sun Apr 19

Vue3-lottie is a component library that enables developers to easily integrate Lottie animations into their Vue 3 and Nuxt 3 applications. It wraps `lottie-web` and provides a declarative API through a `<Vue3Lottie>` component, supporting a wide range of Lottie features like autoplay, looping, speed control, and segment playback. The current stable version is 3.3.1, with frequent patch and minor releases addressing bugs, improving types, and adding features. Key differentiators include its strong TypeScript support (enhanced in v3.0.0), seamless integration with the Vue ecosystem, and specific guidance for Nuxt 3. It abstracts away much of the complexity of directly using `lottie-web`, making it accessible for Vue developers. The library is actively maintained, ensuring compatibility with the latest Vue and Nuxt versions.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate and control a Lottie animation using the `Vue3Lottie` component in a Vue 3 application. It shows basic setup with local animation data, controlling playback direction, and handling component mount events. Remember to replace `./assets/lottie-animation.json` with your actual Lottie JSON file.

<!-- src/App.vue or a component file -->
<template>
  <div id="app">
    <h1>My Lottie Animation</h1>
    <Vue3Lottie
      :animationData="AnimationData"
      :height="200"
      :width="200"
      :loop="true"
      :autoplay="true"
      :speed="1"
      :direction="direction"
      @vnode-mounted="handleLottieMount"
    />
    <button @click="toggleDirection">Toggle Direction</button>
    <p>Current Direction: {{ direction }}</p>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import Vue3Lottie from 'vue3-lottie';
import AnimationData from './assets/lottie-animation.json'; // Assume you have a Lottie JSON file here

export default defineComponent({
  name: 'App',
  components: {
    Vue3Lottie,
  },
  setup() {
    const direction = ref(1); // 1 for forward, -1 for backward

    const toggleDirection = () => {
      direction.value = direction.value === 1 ? -1 : 1;
    };

    const handleLottieMount = (instance: any) => {
      console.log('Lottie component mounted:', instance);
      // You can access the lottie-web instance here if needed
    };

    return {
      AnimationData,
      direction,
      toggleDirection,
      handleLottieMount,
    };
  },
});
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

view raw JSON →