Vue Confetti Component

2.3.0 · maintenance · verified Sun Apr 19

vue-confetti is a versatile Vue component and plugin designed for generating dynamic confetti effects within web applications. It allows developers to programmatically trigger, stop, and customize confetti showers through a `$confetti` instance injected into Vue components. The library supports various particle shapes including circles, rectangles, hearts, and custom images, along with extensive customization for colors, sizes, drop rates, and wind effects. Currently at version 2.3.0, it offers compatibility with both Vue 2 and Vue 3, with Vue 3 support introduced in February 2022. While releases are not frequent, they typically address bug fixes or add minor features, responding to ecosystem changes like Vue 3 adoption. Its primary advantage lies in providing a declarative and easily configurable solution for celebratory UI effects without direct canvas API manipulation, simplifying the process for adding dynamic visual flair.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install and use vue-confetti in a Vue 3 application with TypeScript, showcasing basic confetti triggering, stopping, and customized effects.

// main.ts or main.js
import { createApp } from 'vue';
import App from './App.vue';
import VueConfetti from 'vue-confetti';

const app = createApp(App);
app.use(VueConfetti);
app.mount('#app');

// App.vue
<template>
  <main>
    <h1>Confetti Time!</h1>
    <button @click="start">Start Confetti</button>
    <button @click="stop">Stop Confetti</button>
    <button @click="love">Show Some Love (Hearts & Circles)</button>
    <p>Click the buttons to trigger confetti effects.</p>
  </main>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  methods: {
    start(): void {
      // Basic confetti with default settings
      (this as any).$confetti.start();
    },
    stop(): void {
      (this as any).$confetti.stop();
    },
    love(): void {
      // Custom confetti with hearts and circles, then start and stop after 3s
      (this as any).$confetti.update({
        particles: [
          { type: 'heart', size: 12 },
          { type: 'circle', size: 8 }
        ],
        defaultColors: [
          'red', 'pink', '#FF69B4', '#E0BBE4', '#957DAD'
        ],
        particlesPerFrame: 5
      });
      (this as any).$confetti.start(); // Must call start() after update()
      setTimeout(() => (this as any).$confetti.stop(), 3000);
    }
  }
});
</script>

<style>
main {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
button {
  margin: 0 10px;
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
}
</style>

view raw JSON →