场景:从天天学农小程序点击banner图,web-view打开公众号页面(321春种节),再把公众号页面分享到朋友圈或者好友
实现思路:
1.公众号321页面添加网页向小程序发送消息的代码
mounted:{
this.wechatShare();
},
methods: {
wechatShare() {
wx.miniProgram.postMessage({
data: {
url:"https://uat-h5.ixuenong.com/wx/marketing/activity312",
title: "天天学农——321春种节!",
imgUrl:"https://ttxn.oss-cn-shenzhen.aliyuncs.com/static/img/log/jqnmLogo.png",
},
});
}
2.在小程序web-view接受
<web-view src="{{url}}" bindmessage="onceBindmessage"></web-view>
onceBindmessage(e) {
this. onShareAppMessage(e);
},
onShareAppMessage(e){
return {
title: e.title,
imageUrl: e.imageUrl,
path: e.path
}
}