小程序分享给朋友

小程序分享给朋友

在dom里添加如下代码,点击按钮触发分享

<button open-type="share">分享</button>

onShareAppMessage 重点是这个事件和data是同级

// 自定义分享给朋友
		onShareAppMessage: function(res) {
			if (res.from === 'button') {
				// 来自页面内转发按钮
				console.log(res.target)
			}
			return {
				// 自定义分享内容,通过右上角三个点
				title: '转发给朋友测试', // 自定义的title
				path: '/pages/myself/myself', // 自定义的页面path
				imageUrl: 'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1245218877,2749263190&fm=26&gp=0.jpg' // 自定义的图片
			}
		},
原文地址:https://www.cnblogs.com/skydragonli/p/13784505.html