Skip to content

ShareSheet 分享面板

底部弹起的分享面板,用于展示各分享渠道对应的操作按钮,不含具体的分享逻辑。

导入

js
import ShareSheet from '@/components/feedback/ShareSheet.vue';

使用方法

基础用法

vue
<template>
  <ShareSheet
    v-model:show="show1"
    :items="[
      { title: '微信', icon: 'wechat' },
      { title: '微博', icon: 'sina' },
      { title: '复制链接', icon: 'link' },
      { title: '分享海报', icon: 'poster' },
      { title: '二维码', icon: 'qrcode' },
    ]"
    @select="onSelect"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import ShareSheet from '@/components/feedback/ShareSheet.vue';
import Toast, { type ToastInstance } from '@/components/feedback/Toast.vue';

const toast = ref<ToastInstance>();
const show1 = ref(false);

function onSelect(item: any) {
  toast.value?.show({
    content: `选中了 ${item.title}`,
    duration: 2000,
  });
}
</script>

多行选项

vue
<template>
  <ShareSheet
    v-model:show="show2"
    :items="[
      [
        { title: '微信', icon: 'wechat' },
        { title: '朋友圈', icon: 'wechat-moments' },
        { title: '微博', icon: 'weibo' },
        { title: 'QQ', icon: 'qq' },
      ],
      [
        { title: '复制链接', icon: 'link' },
        { title: '分享海报', icon: 'poster' },
        { title: '二维码', icon: 'qrcode' },
        { title: '小程序码', icon: 'wechat-app-qrcode' },
      ]
    ]"
    @select="onSelect"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import ShareSheet from '@/components/feedback/ShareSheet.vue';
import Toast, { type ToastInstance } from '@/components/feedback/Toast.vue';

const toast = ref<ToastInstance>();
const show2 = ref(false);

function onSelect(item: any) {
  toast.value?.show({
    content: `选中了 ${item.title}`,
    duration: 2000,
  });
}
</script>

自定义图标

vue
<template>
  <ShareSheet
    v-model:show="show3"
    :items="[
      { title: '自定义分享', icon: 'warning' },
      { title: '自定义2', icon: 'https://imengyu.top/assets/images/test/2.jpg' },
      { title: '自定义3', icon: 'qqzone' },
      { title: '自定义4', icon: 'wechat' },
    ]"
    @select="onSelect"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import ShareSheet from '@/components/feedback/ShareSheet.vue';
import Toast, { type ToastInstance } from '@/components/feedback/Toast.vue';

const toast = ref<ToastInstance>();
const show3 = ref(false);

function onSelect(item: any) {
  toast.value?.show({
    content: `选中了 ${item.title}`,
    duration: 2000,
  });
}
</script>

显示描述信息

vue
<template>
  <ShareSheet
    v-model:show="show4"
    title="分享"
    description="请选择您要分享的渠道"
    :items="[
      { title: '微信', icon: 'wechat' },
      { title: '微博', icon: 'weibo' },
      { title: '复制链接', icon: 'link' },
      { title: '分享海报', icon: 'poster' },
      { title: '二维码', icon: 'qrcode' },
    ]"
    @select="onSelect"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import ShareSheet from '@/components/feedback/ShareSheet.vue';
import Toast, { type ToastInstance } from '@/components/feedback/Toast.vue';

const toast = ref<ToastInstance>();
const show4 = ref(false);

function onSelect(item: any) {
  toast.value?.show({
    content: `选中了 ${item.title}`,
    duration: 2000,
  });
}
</script>

API 参考

Props

名称说明类型必填默认值
show是否显示分享面板boolean-false
items分享选项列表,支持二维数组来展示多行数据(ShareSheetItem[])|ShareSheetItem[][]true-
title顶部标题string--
description选项上方的描述信息string--
cancelText取消按钮文字string-取消
showCancel是否显示取消按钮boolean-true
itemStyle选项条目样式ViewStyle--
itemTextStyle选项条目文字样式TextStyle--

ShareSheetItem

名称说明类型必填默认值
title选项名称stringtrue-
icon图标名称或图片链接string--
color图标颜色string--
backgroundColor图标背景色string--
disabled是否禁用boolean-false

Slots

名称说明
default自定义内容,默认会展示 ShareSheet 的全部内容
content自定义分享选项区域

Events

名称说明参数
update:show显示状态改变时触发value: boolean
select选择分享选项时触发item: ShareSheetItem

主题变量

通过修改这些变量,您可以自定义组件的样式:

名称说明默认值
ShareSheetItemIconSize选项图标尺寸70
ShareSheetItemWidth选项宽度25%
ShareSheetItemPaddingVertical选项垂直内边距25
ShareSheetItemPaddingHorizontal选项水平内边距0
ShareSheetItemTextMarginTop选项文字上外边距15
ShareSheetItemTextFontSize选项文字字体大小26
ShareSheetCancelBackgroundColor取消按钮背景色light
ShareSheetCancelPaddingTop取消按钮上内边距20
ShareSheetCancelBold取消按钮文字是否加粗false
ShareSheetCancelColor取消按钮文字颜色text.content