Skip to content

ShareSheet - Vant 4

ShareSheet

Intro

A pop-up sharing panel at the bottom for displaying the action buttons corresponding to each sharing channel, without specific sharing logic.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { ShareSheet } from'vant'; const app = createApp(); app.use(ShareSheet);

Usage

Basic Usage

html
js
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const showShare = ref(false); const options = [ { name: 'WeChat', icon: 'wechat' }, { name: 'Weibo', icon: 'weibo' }, { name: 'Link', icon: 'link' }, { name: 'Poster', icon: 'poster' }, { name: 'Qrcode', icon: 'qrcode' }, ]; constonSelect = (option) => { showToast(option.name); showShare.value = false; }; return { options, onSelect, showShare, }; }, };

Multi Line

html
js
import { ref } from'vue'; exportdefault { setup() { const showShare = ref(false); const options = [ [ { name: 'WeChat', icon: 'wechat' }, { name: 'WeChat Moments', icon: 'wechat-moments' }, { name: 'Weibo', icon: 'weibo' }, { name: 'QQ', icon: 'qq' }, ], [ { name: 'Link', icon: 'link' }, { name: 'Poster', icon: 'poster' }, { name: 'Qrcode', icon: 'qrcode' }, { name: 'Weapp Qrcode', icon: 'weapp-qrcode' }, ], ]; return { options, showShare, }; }, };

Custom Icon

html
js
import { ref } from'vue'; exportdefault { setup() { const showShare = ref(false); const options = [ { name: 'Name', icon: 'https://fastly.jsdelivr.net/npm/@vant/assets/custom-icon-fire.png', }, { name: 'Name', icon: 'https://fastly.jsdelivr.net/npm/@vant/assets/custom-icon-light.png', }, { name: 'Name', icon: 'https://fastly.jsdelivr.net/npm/@vant/assets/custom-icon-water.png', }, ]; return { options, showShare, }; }, };

Show Description

html
js
import { ref } from'vue'; exportdefault { setup() { const showShare = ref(false); const options = [ { name: 'WeChat', icon: 'wechat' }, { name: 'Weibo', icon: 'weibo' }, { name: 'Link', icon: 'link', description: 'Description' }, { name: 'Poster', icon: 'poster' }, { name: 'Qrcode', icon: 'qrcode' }, ]; return { options, showShare, }; }, };

API

Props

AttributeDescriptionTypeDefault
v-model:showWhether to show ShareSheetbooleanfalse
optionsShare optionsOption[][]
titleTitlestring-
cancel-textCancel button textstring'Cancel'
descriptionDescriptionstring-
durationTransition duration, unit second*numberstring*
z-indexSet the z-index to a fixed value*numberstring*
roundWhether to show round cornerbooleantrue
overlayWhether to show overlaybooleantrue
overlay-classCustom overlay class*stringArray
overlay-styleCustom overlay styleobject-
lock-scrollWhether to lock background scrollbooleantrue
lazy-renderWhether to lazy render util appearedbooleantrue
close-on-popstateWhether to close when popstatebooleantrue
close-on-click-overlayWhether to close when overlay is clickedbooleantrue
safe-area-inset-bottomWhether to enable bottom safe area adaptationbooleantrue
teleportSpecifies a target element where ShareSheet will be mounted*stringElement*
before-closeCallback function before close*(action: string) => booleanPromise<boolean>*

Data Structure of Option

KeyDescriptionType
nameOption namestring
descriptionOption descriptionstring
iconOption icon, can be set to wechat``weibo``qq``link``qrcode``poster``weapp-qrcode``wechat-moments or image URLstring
classNameOption className is used to set the class props to the share itemstring

Events

EventDescriptionArguments
selectEmitted when an option is clickedoption: Option, index: number
cancelEmitted when the cancel button is clicked-
openEmitted when opening ShareSheet-
closeEmitted when closing ShareSheet-
openedEmitted when ShareSheet is opened-
closedEmitted when ShareSheet is closed-
click-overlayEmitted when overlay is clickedevent: MouseEvent

Slots

NameDescription
titleCustom title
descriptionCustom description
cancelCustom the content of cancel button

Types

The component exports the following type definitions:

ts
importtype { ShareSheetProps, ShareSheetOption, ShareSheetOptions, } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-share-sheet-header-paddingvar(--van-padding-sm) var(--van-padding-md) var(--van-padding-base)-
--van-share-sheet-title-colorvar(--van-text-color)-
--van-share-sheet-title-font-sizevar(--van-font-size-md)-
--van-share-sheet-title-line-heightvar(--van-line-height-md)-
--van-share-sheet-description-colorvar(--van-text-color-2)-
--van-share-sheet-description-font-sizevar(--van-font-size-sm)-
--van-share-sheet-description-line-height16px-
--van-share-sheet-icon-size48px-
--van-share-sheet-option-name-colorvar(--van-gray-7)-
--van-share-sheet-option-name-font-sizevar(--van-font-size-sm)-
--van-share-sheet-option-description-colorvar(--van-text-color-3)-
--van-share-sheet-option-description-font-sizevar(--van-font-size-sm)-
--van-share-sheet-cancel-button-font-sizevar(--van-font-size-lg)-
--van-share-sheet-cancel-button-height48px-
--van-share-sheet-cancel-button-backgroundvar(--van-background-2)-

Enterprise-level mobile solution based on Vant