微信小程式 之 分享給朋友 以及二維碼傳參及接收
阿新 • • 發佈:2020-07-22
1、分享給朋友
分享給朋友是小程式自帶API:onShareAppMessage
button元件配置open-type='share'
<button class="mini-btn" type="primary" size="mini" bindtap="handleCode" data-type="replay" data-url="{{erweiCOde}}" open-type="share" data-EMcode="{{employeeCode}}">傳送給朋友</button>
JS
onShareAppMessage: function(res) { console.log(res) let that= this; const obj = { title: "傳送給好友", imageUrl: that.data.erweiCOde, path: '/pages/login/index?employeeCode='+res.target.dataset.emcode,(開啟路徑,在開啟頁面裡的onload裡接收引數) success: function(res) { console.log(res, "轉發成功") }, fail: function(res) { wx.showToast({ title:'傳送失敗', icon:'none' }) } } return obj }
2、小程式二維碼生成
小程式二維碼生成一般是後端提供介面,前端請求的時候只要進行引數配置
主要引數:
①、scene:要攜帶的引數
②、path:掃二維碼要進入的頁面路徑
要注意的是二維碼進入進入的頁面引數的接收(在要進入頁面的onload裡面)
一定要用decodeURIComponent() 進行二維碼解析