ShareSheet 分享面板
引入
在或index.json
中引入组件,详细介绍见。
基础用法
<van-cell title="显示分享面板" bind:click="onClick" />
<van-share-sheet
show="{{ showShare }}"
title="立即分享给好友"
options="{{ options }}"
bind:select="onSelect"
bind:close="onClose"
/>
Page({
data: {
showShare: false,
options: [
{ name: '微信', icon: 'wechat', openType: 'share' },
{ name: '微博', icon: 'weibo' },
{ name: '复制链接', icon: 'link' },
{ name: '二维码', icon: 'qrcode' },
],
},
onClick(event) {
this.setData({ showShare: true });
},
onClose() {
this.setData({ showShare: false });
},
onSelect(event) {
this.onClose();
},
});
当分享选项的数量较多时,可以将 options
定义为数组嵌套的格式,每个子数组会作为一行选项展示。
Page({
data: {
showShare: false,
options: [
[
{ name: '微信', icon: 'wechat' },
{ name: '微博', icon: 'weibo' },
{ name: 'QQ', icon: 'qq' },
],
[
{ name: '分享海报', icon: 'poster' },
{ name: '二维码', icon: 'qrcode' },
],
],
},
});
自定义图标
<van-share-sheet show="{{ showShare }}" options="{{ options }}" />
展示描述信息
通过 description
属性可以设置标题下方的描述文字, 在 options
内设置 description
属性可以添加分享选项描述。
<van-share-sheet
show="{{ showShare }}"
options="{{ options }}"
title="立即分享给好友"
description="描述信息"
Page({
data: {
showShare: false,
options: [
{ name: '微信', icon: 'wechat' },
{ name: '微博', icon: 'weibo' },
{
name: '复制链接',
icon: 'link',
description: '描述信息',
},
{ name: '分享海报', icon: 'poster' },
{ name: '二维码', icon: 'qrcode' },
],
});