Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useShare.md
1---2category: Browser3---45# useShare67Reactive [Web Share API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share). The Browser provides features that can share content in text or file.89> The `share` method has to be called following a user gesture like a button click. It can’t simply be called on page load for example. That’s in place to help prevent abuse.1011## Usage1213```ts14import { useShare } from '@vueuse/core'1516const { share, isSupported } = useShare()1718function startShare() {19share({20title: 'Hello',21text: 'Hello my friend!',22url: location.href,23})24}25```2627### Passing a source ref2829You can pass a `ref` to it, changes from the source ref will be reflected to your sharing options.3031```ts {6}32import { ref } from 'vue'3334const shareOptions = ref<ShareOptions>({ text: 'foo' })35const { share, isSupported } = useShare(shareOptions)3637shareOptions.value.text = 'bar'3839share()40```4142## Type Declarations4344```ts45export interface UseShareOptions {46title?: string47files?: File[]48text?: string49url?: string50}51export interface UseShareReturn extends Supportable {52share: (overrideOptions?: MaybeRefOrGetter<UseShareOptions>) => Promise<void>53}54/**55* Reactive Web Share API.56*57* @see https://vueuse.org/useShare58* @param shareOptions59* @param options60*61* @__NO_SIDE_EFFECTS__62*/63export declare function useShare(64shareOptions?: MaybeRefOrGetter<UseShareOptions>,65options?: ConfigurableNavigator,66): UseShareReturn67```68