微信小程序 转发 分享功能

原文链接:https://blog.csdn.net/onion_line/article/details/83036502

官网文档:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html

第一种情况 点击小程序转发

不加入参数


   
   
   
   
  1. //转发
  2. onShareAppMessage: function() {
  3. let users = wx.getStorageSync( 'user');
  4. if (res.from === 'button') {}
  5. return {
  6. title: '转发',
  7. path: '/pages/index/index',
  8. success: function(res) {}
  9. }
  10. }

加入参数


   
   
   
   
  1. //转发
  2. onShareAppMessage: function() {
  3. let users = wx.getStorageSync( 'user');
  4. if (res.from === 'button') {}
  5. return {
  6. title: '转发',
  7. path: '/pages/index/index?from_uid=' + users.id,
  8. success: function(res) {}
  9. }
  10. }

 

第二种 分享

这个分享必须做成button 且加上 open-type="share"

不加入参数


   
   
   
   
  1. onShareAppMessage: function (res) {
  2. if (res.from === 'button') {
  3. }
  4. return {
  5. title: '转发',
  6. path: '/pages/index/community/topic/topic',
  7. success: function (res) {
  8. console.log( '成功', res)
  9. }
  10. }
  11. }

加入参数 


   
   
   
   
  1. //转发
  2. onShareAppMessage: function (res) {
  3. if (res.from === 'button') {
  4. }
  5. return {
  6. title: '转发',
  7. path: '/pages/index/community/topic/topic?jsonStr=' + this.data.list,
  8. success: function (res) {
  9. console.log( '成功', res)
  10. }
  11. }
  12. }

提醒:

这里转发的参数要在onLoad 的options 运用

 

你可能感兴趣的:(微信小程序)