Vue Lottie Animation Wrapper (Vue 2)

0.2.1 · abandoned · verified Tue Apr 21

vue-lottie is a Vue 2 component designed to display Lottie animations, acting as a wrapper for the `bodymovin.js` library (now known as `lottie-web`). The package, currently at version `0.2.1`, was last published approximately eight years ago, indicating it is no longer actively maintained. It primarily supports Vue 2.x applications and leverages the Lottie animation format for creating lightweight, scalable vector animations exported from Adobe After Effects. While it provides basic functionality for playing, pausing, and controlling animation speed, its age means it lacks support for modern Vue 3 applications and the latest features or optimizations of `lottie-web`. Developers seeking Lottie integration in contemporary Vue projects should consider actively maintained alternatives like `vue3-lottie` or `lottie-web-vue` which offer Vue 3 and TypeScript support. The package's key differentiator was its early integration of Lottie with Vue 2, providing a declarative component interface for simple animation playback.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and register the Lottie component locally, load animation JSON data, and control playback (play, pause, stop, speed) using component methods.

<template>
    <div id="app">
        <lottie :options="defaultOptions" :height="400" :width="400" v-on:animCreated="handleAnimation"/>
        <div>
            <p>Speed: x{{animationSpeed}}</p>
            <input type="range" value="1" min="0" max="3" step="0.5"
                   v-on:change="onSpeedChange" v-model="animationSpeed">
        </div>
        <button v-on:click="stop">stop</button>
        <button v-on:click="pause">pause</button>
        <button v-on:click="play">play</button>
    </div>
</template>

<script>
  import Lottie from 'vue-lottie'; // Corrected import for npm package
  import * as animationData from './assets/pinjump.json'; // Ensure this path is correct for your project

  export default {
    name: 'app',
    components: {
      'lottie': Lottie
    },
    data() {
      return {
        defaultOptions: {animationData: animationData},
        animationSpeed: 1,
        anim: null // Initialize anim to null
      }
    },
    methods: {
      handleAnimation: function (anim) {
        this.anim = anim;
      },

      stop: function () {
        if (this.anim) this.anim.stop();
      },

      play: function () {
        if (this.anim) this.anim.play();
      },

      pause: function () {
        if (this.anim) this.anim.pause();
      },

      onSpeedChange: function () {
        if (this.anim) this.anim.setSpeed(this.animationSpeed);
      }
    }
  }
</script>

view raw JSON →