Vue UUID Integration

3.0.0 · active · verified Sun Apr 19

vue-uuid is a specialized library for integrating UUID generation capabilities directly into Vue.js applications. The current stable version, 3.0.0, exclusively supports Vue 3, with previous versions like 2.1.0 available for Vue 2 compatibility. It provides convenient access to UUID generation methods (v1, v3, v4, v5) directly on the Vue instance via `$uuid`, making them readily available within component templates and scripts. Additionally, it exports a standalone `uuid` object for use outside the Vue instance. While many general-purpose UUID libraries exist, vue-uuid differentiates itself by streamlining the integration specifically for the Vue ecosystem, abstracting away common setup boilerplate and providing a consistent API within the Vue context. Its release cadence appears to be tied to major Vue version updates, ensuring compatibility with the latest framework changes.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install `vue-uuid` by wrapping `createApp` with `withUUID` and then accessing UUID generation methods via `$uuid` within a component's template and script.

import { createApp } from 'vue';
import withUUID from 'vue-uuid';

const NAMESPACE = "65f9af5d-f23f-4065-ac85-da725569fdcd";

const app = withUUID(
  createApp({
    data() {
      return {
        NAMESPACE,
        uuid: '',
      };
    },
    mounted() {
      // Access $uuid on the instance
      this.uuid = this.$uuid.v1();
    },
    template: `
      <div class="uuid-panel">
        <h3 class="uuid">{{ uuid }}</h3>
        <button @click="uuid = $uuid.v1()">Generate V1</button>
        <button @click="uuid = $uuid.v3()">Generate V3</button>
        <button @click="uuid = $uuid.v4()">Generate V4</button>
        <button @click="uuid = $uuid.v5('Name 1', NAMESPACE)">Generate V5</button>
      </div>
    `
  })
);

app.mount('#app');

view raw JSON →