readme.md 2.4 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3
#### 本功能基于[底部图标菜单](https://ext.dcloud.net.cn/plugin?id=4858)封装而成。
### 示例代码
```
DCloud_JSON's avatar
DCloud_JSON 已提交
4 5 6 7 8 9
<template>
	<button type="default" @click="uniShare">显示</button>
</template>
<script>
	import uniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
	export default {
study夏羽's avatar
study夏羽 已提交
10 11 12 13 14 15 16 17 18
		onBackPress({from}) {
			console.log(from);
			if(from=='backbutton'){
				this.$nextTick(function(){
					uniShare.hide()
				})
				return uniShare.isShow;
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
19 20
		methods: {
			uniShare() {
21
				uniShare.show({
DCloud_JSON's avatar
DCloud_JSON 已提交
22 23 24 25 26 27 28 29
					content: { //公共的分享参数配置  类型(type)、链接(herf)、标题(title)、summary(描述)、imageUrl(缩略图)
						type: 0,
						href: 'https://uniapp.dcloud.io/',
						title: '标题',
						summary: '描述',
						imageUrl: 'https://img-cdn-aliyun.dcloud.net.cn/stream/icon/__UNI__HelloUniApp.png'
					},
					menus: [{
Anne_LXM's avatar
Anne_LXM 已提交
30
							"img": "/static/app/sharemenu/wechatfriend.png",
DCloud_JSON's avatar
DCloud_JSON 已提交
31 32 33 34 35 36 37
							"text": "微信好友",
							"share": { //当前项的分享参数配置。可覆盖公共的配置如下:分享到微信小程序,配置了type=5
								"provider": "weixin",
								"scene": "WXSceneSession"
							}
						},
						{
Anne_LXM's avatar
Anne_LXM 已提交
38
							"img": "/static/app/sharemenu/wechatmoments.png",
DCloud_JSON's avatar
DCloud_JSON 已提交
39 40 41
							"text": "微信朋友圈",
							"share": {
								"provider": "weixin",
study夏羽's avatar
study夏羽 已提交
42
								"scene": "WXSceneTimeline"
DCloud_JSON's avatar
DCloud_JSON 已提交
43 44 45
							}
						},
						{
Anne_LXM's avatar
Anne_LXM 已提交
46
							"img": "/static/app/sharemenu/mp_weixin.png",
DCloud_JSON's avatar
DCloud_JSON 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60
							"text": "微信小程序",
							"share": {
								provider: "weixin",
								scene: "WXSceneSession",
								type: 5,
								miniProgram: {
									id: '123',
									path: '/pages/list/detail',
									webUrl: '/#/pages/list/detail',
									type: 0
								},
							}
						},
						{
Anne_LXM's avatar
Anne_LXM 已提交
61
							"img": "/static/app/sharemenu/weibo.png",
DCloud_JSON's avatar
DCloud_JSON 已提交
62 63 64 65 66 67
							"text": "微博",
							"share": {
								"provider": "sinaweibo"
							}
						},
						{
Anne_LXM's avatar
Anne_LXM 已提交
68
							"img": "/static/app/sharemenu/qq.png",
DCloud_JSON's avatar
DCloud_JSON 已提交
69 70 71 72 73 74
							"text": "QQ",
							"share": {
								"provider": "qq"
							}
						},
						{
Anne_LXM's avatar
Anne_LXM 已提交
75
							"img": "/static/app/sharemenu/copyurl.png",
DCloud_JSON's avatar
DCloud_JSON 已提交
76 77 78 79
							"text": "复制",
							"share": "copyurl"
						},
						{
Anne_LXM's avatar
Anne_LXM 已提交
80
							"img": "/static/app/sharemenu/more.png",
DCloud_JSON's avatar
DCloud_JSON 已提交
81 82 83 84 85 86
							"text": "更多",
							"share": "shareSystem"
						}
					],
					cancelText: "取消分享",
				}, e => { //callback
study夏羽's avatar
study夏羽 已提交
87
					console.log(uniShare.isShow);
DCloud_JSON's avatar
DCloud_JSON 已提交
88 89 90 91 92
					console.log(e);
				})
			}
		}
	}
93 94
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
95
```