Vue Lottie Player

2.0.2 · active · verified Tue Apr 21

Vue Lottie Player is a type-safe Vue 3 component and plugin for integrating Lottie animations into web applications, built as a wrapper around the `lottie-web` library. The current stable version is 2.0.2. This library prioritizes security and performance by offering a default 'light-player' build that is CSP-friendly and avoids `unsafe-eval`, alongside an opt-in '/full' entry for animations requiring After Effects expressions. It provides a robust API for both URL- and JSON-based animation sources, imperative ref controls for direct playback manipulation, and straightforward integration with Nuxt 3. Its key differentiators include built-in TypeScript types, a focus on CSP compliance, and a clear separation between a lean default build and a feature-rich full build.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the component, stylesheet, and types, then rendering a Lottie animation from a URL with basic controls.

import { ref } from 'vue';
import type { AnimationItem } from 'lottie-web';
import 'vue-lottie-player/style.css';
import type { LottieUrlSource, LottieDataSource, VueLottiePlayerInstance } from 'vue-lottie-player';
import { VueLottiePlayer } from 'vue-lottie-player';

// Assuming you have an animation JSON file at /animations/sample-animation.json
// Or if using local data:
// import demoAnimationData from './assets/demo-animation.json';

const sourceUrl: LottieUrlSource = {
  kind: 'url',
  value: '/animations/sample-animation.json'
};

// Example for local JSON data:
// const sourceData: LottieDataSource = {
//   kind: 'data',
//   value: demoAnimationData
// };

const playerRef = ref<VueLottiePlayerInstance | null>(null);

function onReady(animation: AnimationItem) {
  console.log('Lottie animation is ready:', animation);
  animation.setSpeed(1.5);
}

function playAnimation() {
  playerRef.value?.play();
}

function pauseAnimation() {
  playerRef.value?.pause();
}

function stopAnimation() {
  playerRef.value?.stop();
}

view raw JSON →