ShareSheet
Filters sharing options by platform capability and emits shared only after a successful supported action.
Import
Use <hui-share-sheet> after configuring uni-app easycom. Import public types and functions from @nscode/handy-uni. Ordinary Vue applications install the @nscode/handy-uni/web preview plugin.
Examples
Each example is standalone. Controls show the current value or event result on the page.
<template>
<view>
<hui-space direction="vertical" fill>
<hui-button custom-class="hui-space__item" @click="visible = true">分享 / Share</hui-button>
<hui-share-sheet
v-model:visible="visible"
custom-class="hui-space__item"
:options="options"
:payload="payload"
@select="onSelect"
@shared="(name) => (lastEvent = 'shared:' + name)"
@close="(reason) => (lastEvent = 'close:' + reason)"
@cancel="lastEvent = 'cancel'"
@open="lastEvent = 'open'"
@opened="lastEvent = 'opened'"
@closed="lastEvent = 'closed'"
/>
<text class="hui-space__item">{{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ShareSheetOption } from '@nscode/handy-uni'
const lastEvent = ref('尚无事件 / No event')
const visible = ref(false)
const onSelect = (option: ShareSheetOption, context: { index: number; row: number }) => {
lastEvent.value = JSON.stringify({ option, context })
}
const options: ('wechat' | 'timeline' | 'link' | 'system')[] = [
'wechat',
'timeline',
'link',
'system'
]
const payload = {
title: '文章 / Article',
desc: '内容摘要 / Summary',
url: 'https://example.com/article',
path: '/pages/article/index?id=1'
}
</script>
Props
| Prop | Type | Default | Details |
|---|---|---|---|
visible | boolean | undefined | Controlled visibility. |
defaultVisible | boolean | false | Initial uncontrolled visibility. |
options | (ShareSheetOption | ShareSheetPreset)[] | (ShareSheetOption | ShareSheetPreset)[][] | [] | One or multiple rows of share options or preset names. |
payload | ShareSheetPayload | — | Title, description, URL, mini-program path and image metadata. |
title | string | — | Heading text, or the title-placeholder switch for Skeleton. |
description | string | — | Supporting text. |
cancelText | string | — | Cancel label; an empty string hides the cancel button. |
closeOnSelect | boolean | true | Requests close after selecting a supported option. |
closeOnClickOverlay | boolean | true | Requests close when the backdrop is clicked. |
beforeClose | (reason: ShareSheetCloseReason) => boolean | void | Promise<boolean | void> | — | Asynchronous close guard; false or rejection leaves the panel open. |
safeAreaInsetBottom | boolean | true | Adds bottom safe-area padding. |
zIndex | number | — | Explicit stacking level. |
rootPortal | boolean | false | Uses a root portal on supported mini-program targets. |
Root classes and styles use customClass and customStyle. Numbers representing dimensions use px; durations use ms unless explicitly documented.
Events
| Event | Arguments |
|---|---|
update:visible | (visible: boolean) |
select | (option: ShareSheetOption, context: { index:number;row:number }) |
shared | (name: string) |
cancel | () |
close | (reason: ShareSheetCloseReason) |
open | () |
opened | () |
closed | () |
Controlled state only changes when the parent accepts its update event. Events with multiple words use kebab-case. Disabled or stale asynchronous actions do not emit a successful state change.
Slots
| Slot | Scope |
|---|---|
preview | — |
option | { option, index, row } |
guide | { preset, close } |
Methods
| Method | Signature | Description |
|---|---|---|
showGuide | (name: string): void | Display sharing guidance. |
Types
ShareSheetPreset、ShareSheetOption、ShareSheetPayload、ShareSheetCloseReason、ShareSheetProps、ShareSheetEmits、ShareSheetExpose.
Platform notes
WeChat friend sharing uses button open-type=share with page onShareAppMessage; timeline uses guidance and page onShareTimeline. Neither pretends to know the sharing outcome. App WeChat/timeline actions require the share adapter. Canceled system sharing does not emit shared. Unsupported presets are hidden. WeChat owns its copy feedback; other targets show Toast after success. Guidance opens after the sheet finishes closing.
Device smoke checklist.