1、在要分享的按鈕上寫一個跳轉
<navigator url="../invite1/invite1"> <button class="invite_btn">立即邀請</button> </navigator>
2、再新建一個頁面invite1,新建一個web-view
wxml頁面
<web-view src="{{shareUrl}}"></web-view>
js頁面
定義一個變量,並對其賦值。
data:{ shareUrl: null }, onLoad: function (options) { var that = this that.setData({ shareUrl: "http://test.meetfit.com.cn/share/active/?userId=" + id + "&userName=" + nickname }) },
3、分享js
onShareAppMessage: function (res) { var that = this if (res.from === 'button') { // 來自頁面內轉發按鈕 console.log(res.target) } return { title: '分享H5', //這一點很重要哦,小程序只能打開自己的頁面,所以需要本地的地址+webViewUrl的地址才行。 path: "/pages/mine/invite1/invite1?url=" +res.webViewUrl, imageUrl: "", success: (res) => { if (res.data.code == 0) { wx.showToast({ title: '發送邀請好友成功', icon: 'success', duration: 2000 }) } else { wx.showToast({ title: res.data.message, icon: 'none', duration: 2000 }) } }, fail: (res) => { console.log("轉發失敗", res); } } }