Vue

Integrate DotPassport widgets with Vue 3 using the Composition API.

Installation

npm install @dotpassport/sdk

Basic Component

<template>
  <div ref="container"></div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted, watch } from 'vue';
import { createWidget, type WidgetConfig } from '@dotpassport/sdk';

interface Props {
  address: string;
  type?: 'reputation' | 'badge' | 'profile' | 'category';
  theme?: 'light' | 'dark' | 'auto';
}

const props = withDefaults(defineProps<Props>(), {
  type: 'reputation',
  theme: 'light'
});

const container = ref<HTMLElement | null>(null);
let widget: ReturnType<typeof createWidget> | null = null;

onMounted(() => {
  if (container.value) {
    widget = createWidget({
      apiKey: import.meta.env.VITE_DOTPASSPORT_API_KEY,
      address: props.address,
      type: props.type,
      theme: props.theme
    });
    widget.mount(container.value);
  }
});

onUnmounted(() => {
  widget?.destroy();
});

watch(() => props.address, (newAddress) => {
  widget?.update({ address: newAddress });
});

watch(() => props.theme, (newTheme) => {
  widget?.update({ theme: newTheme });
});
</script>

Reputation Widget Component

Usage


Composable Hook

Usage


Multiple Widgets


With Pinia Store


Nuxt 3 Integration


Last updated