Skip to main content

Vue Integration

GUN integrates naturally with Vue.js’s reactive data system, providing real-time synchronization across clients.

Installation

1

Install GUN

Add GUN to your Vue project:
2

Include GUN in your Vue app

Import GUN in your main.js or component:
3

Initialize GUN

Create a GUN instance and connect to peers:

Basic Usage

Here’s a complete example of a Todo app using GUN with Vue:

Vue 3 Composition API

For Vue 3 applications using the Composition API:

Creating a GUN Plugin for Vue

You can create a Vue plugin to make GUN available throughout your app:
Usage in main.js:
Using in components:

Vuex Integration

Integrate GUN with Vuex for centralized state management:

Community Packages

Check out these community-maintained Vue + GUN packages:

Best Practices

  1. Use computed properties: Filter GUN data in Vue computed properties for reactive updates
  2. Clean up listeners: Remove GUN listeners when components are destroyed
  3. Avoid direct mutations: Use GUN’s .put() method to update data, not Vue’s reactive assignments
  4. Filter metadata: GUN uses _ keys for metadata - filter these in your display logic

Reactive Patterns

Two-way Data Binding

Next Steps