A Vue 3 Composition API component (compatible with Nuxt 3) wrapping the core vanilla JS library, following the same lifecycle pattern as src/social-share-button-react.jsx:
<template>
<div ref="container"></div>
</template>
<script setup>
import { ref, onMounted, onBeforeUnmount, watch } from 'vue';
const props = defineProps({
url: { type: String, default: '' },
title: { type: String, default: '' },
description: { type: String, default: '' },
hashtags: { type: Array, default: () => [] },
via: { type: String, default: '' },
platforms: { type: Array, default: () => ['whatsapp', 'facebook', 'twitter', 'linkedin', 'telegram', 'reddit'] },
theme: { type: String, default: 'dark' },
buttonText: { type: String, default: 'Share' },
customClass: { type: String, default: '' },
onShare: { type: Function, default: null },
onCopy: { type: Function, default: null },
buttonStyle: { type: String, default: 'default' },
modalPosition: { type: String, default: 'center' }
});
const container = ref(null);
let shareButton = null;
onMounted(() => {
// SSR guard β Nuxt pre-renders on the server
if (typeof window !== 'undefined' && window.SocialShareButton) {
shareButton = new window.SocialShareButton({
container: container.value,
url: props.url || window.location.href,
title: props.title || document.title,
description: props.description,
hashtags: props.hashtags,
via: props.via,
platforms: props.platforms,
theme: props.theme,
buttonText: props.buttonText,
customClass: props.customClass,
onShare: props.onShare,
onCopy: props.onCopy,
buttonStyle: props.buttonStyle,
modalPosition: props.modalPosition
});
}
});
onBeforeUnmount(() => {
if (shareButton) {
shareButton.destroy();
shareButton = null;
}
});
// Sync prop changes to the underlying vanilla JS instance (e.g. Nuxt route changes)
watch(props, (newProps) => {
if (shareButton) {
shareButton.updateOptions(newProps);
}
}, { deep: true });
<\/script>
<!-- pages/index.vue -->
<template>
<SocialShareButton
url="https://your-website.com"
title="Check this out!"
description="An amazing website"
theme="dark"
button-text="Share"
/>
</template>
<script setup>
// Component is auto-imported from components/ in Nuxt 3
<\/script>
π― Direction
SocialShareButton is a lightweight, zero-dependency, framework-agnostic social sharing component. The goal of this issue is to extend first-class support to Nuxt.js (the Vue meta-framework), which is SSR-first. Since Nuxt renders on the server, the wrapper must guard all browser APIs with
typeof window !== 'undefined'checks and only initialize the button on the client side usingonMounted.πΉ See the button in action: https://youtu.be/cLJaT-8rEvQ?si=CLipA0Db4WL0EqKM
π Files to Create / Modify
β New File:
src/social-share-button-nuxt.vueA Vue 3 Composition API component (compatible with Nuxt 3) wrapping the core vanilla JS library, following the same lifecycle pattern as
src/social-share-button-react.jsx:β Existing File:
index.htmlβ Add Nuxt.js Integration SectionMirror the existing
βοΈ React Integrationsection. Add a new section block with:π Nuxt.js Integrationcomponents/)pages/index.vuefileExample code snippet to display in the demo section:
β Acceptance Criteria
src/social-share-button-nuxt.vuecreated using Vue 3 Composition API (script setup)typeof window !== 'undefined') present on all browser API usages insideonMountedonMountedused for initialization,onBeforeUnmountcallsdestroy()to prevent memory leakswatch(props, ...)with{ deep: true }callsupdateOptions()on prop changescomponents/directoryindex.htmlupdated with a Nuxt.js section containing install + usage code snippetsindex.html