onShareAppMessage: function (options) { //監測頁面按鈕分享 if (options.from === 'button') { console.log(options.target) } var that = this; return { //標題 title: "title", // 路徑(path)是app.json里配置的路徑 path: 'pages/yeles/yeles?orderid=' + that.data.da.id, success: function (res) { //轉發成功的回調 console.log(res) if (res.errMsg == 'shareAppMessage:ok') { } }, fail: function (res) { //轉發取消或失敗的回調 if (res.errMsg == 'shareAppMessage:fail cancel') { wx.showToast({ title: '轉發取消', }) } else if (res.errMsg == 'shareAppMessage:fail') { wx.showToast({ title: '轉發失敗', }) } } } },
在邏輯層定義了onShareAppMessage函數,用戶才可以點擊右上角的菜單分享
另外一種觸發分享是button,<button openType="share" > 定義這樣一個屬性為openType,值為share的按鈕也可以觸發分享
分享推薦:
商品分享帶參:商品id和用戶id
砍價分享:訂單id
當時上傳分享的時候入了個坑:
不止是分享,然后還有小程序本身,再上傳的時候盡量把測試的console.log全部去掉。可能也是當時測試沒細心,console一個字段報了個錯,導致下面的流程沒有走,其實把console去掉了什么事都沒有了,