import{o as t,a,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},l=n(`

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.

import { createApp } from 'vue';
import { ShareSheet } from 'vant';

const app = createApp();
app.use(ShareSheet);

Usage

Basic Usage

<van-cell title="Show ShareSheet" @click="showShare = true" />
<van-share-sheet
  v-model:show="showShare"
  title="Share"
  :options="options"
  @select="onSelect"
/>
import { ref } from 'vue';
import { Toast } from 'vant';

export default {
  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' },
    ];

    const onSelect = (option) => {
      Toast(option.name);
      showShare.value = false;
    };

    return {
      options,
      onSelect,
      showShare,
    };
  },
};

Multi Line

<van-share-sheet v-model:show="showShare" title="Share" :options="options" />
import { ref } from 'vue';

export default {
  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

<van-share-sheet v-model:show="showShare" :options="options" />
import { ref } from 'vue';

export default {
  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

<van-share-sheet
  v-model:show="showShare"
  :options="options"
  title="Share"
  description="Description"
/>
import { ref } from 'vue';

export default {
  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 secondnumber | string0.3
round v3.2.6Whether to show round cornerbooleantrue
overlayWhether to show overlaybooleantrue
overlay-classCustom overlay classstring | Array | object-
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 mountedstring | Element-
before-close v3.1.4Callback function before close(action: string) => boolean | Promise<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
cancel v3.0.10Custom the content of cancel button

Types

The component exports the following type definitions:

import type {
  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-color-light)-
`,16),d=[l],i={__name:"README",setup(p,{expose:s}){return s({frontmatter:{}}),(o,c)=>(t(),a("div",e,d))}};export{i as default};