uniapp 微信小程序端分享到微信朋友圈 (坑)

uniapp 微信小程序端分享到微信朋友圈 (坑)

  1. 首先必须要有这两个函数 onShareAppMessage onShareTimeline 这两个函数跟data平级
  2. 然后是这两个函数的内容如下 参数res需要传,即使不用
onShareAppMessage(res) {
			return {
				title: this.title,
				path: this.path,
				imageUrl: this.dispose.shareImg
			};
		},
		// 自定义页面的分享到朋友圈
		onShareTimeline(res) {
			return {
				title: this.title,
				query: this.query,
				imageUrl: this.dispose.shareImg,
			}
		},
  1. 不要在函数里面请求接口,或者写逻辑,因为return会先走,在里面写逻辑很大概率会导致,自定义title,自定义图片失效。
  2. onShareTimeline 分享朋友圈的属性是query不需要path 文档如下在这里插入图片描述
  3. 以上只针对分享到朋友圈

注:如果你的项目中使用了 uni-simple-router 这个插件的话,在获取参数的时候可能会有点复杂,下面是我的代码,仅供参考

if (JSON.stringify(this.$Route.query) != "{}") {
				console.log('这是分享数据', this.$Route.query)
			} else if (options != undefined) {
				console.log('这是分享数据1', options)
			}else{
				const pages=getCurrentPages()
				// 当前页面
				const page = pages[pages.length - 1]
				console.log('这是分享数据2',page.options)
			}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值