小程序webview页面分享到小程序

h5页面

import wx from "weixin-js-sdk";



wx.miniProgram.postMessage({
   data: {
   shareTitle: this.goodsInfo.name,
   imageUrl: this.goodsInfo.image,
   shareUrl:`/pages/goods_details/goods_detailsid=${this.goodsInfo.id}&agent_id=${user_id}`
   }
})

执行这个方法后,必须设置引导页面,让用户主动点击右上角分享后才行

在小程序webview页面拿参数

<web-view :src="url" @message="handleMessage"></web-view>

methods: {
		handleMessage(evt) {
			console.log(evt,'分享参数');
            //evt.detail.data是一个数组,每次分享会往数组后面叠加,所以取最后一个值
			let data=evt.detail.data
			this.imageUrl=data[data.length-1].imageUrl
			this.shareTitle=data[data.length-1].shareTitle
			this.shareUrl=data[data.length-1].shareUrl
		},
	},
	onShareAppMessage(options) {
		return {
			title: this.shareTitle,
			path: this.shareUrl,
			imageUrl:this.imageUrl
		};
	},

猜你喜欢

转载自blog.csdn.net/m0_59203969/article/details/134293318