wechat-小程序-分享

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangxuan0261/article/details/83505437

title: wechat-小程序-分享
categories: Wechat
tags: [wechat, 分享, 小程序]
date: 2018-10-29 14:13:18
comments: false

参考文档


触发分享的两种方式

  1. 右上角菜单

  2. 页面 自定义按钮

    只需要在 button 标签中加入 open-type="share"

    <view class="btn-area">
        <button type="primary" open-type="share">分享</button>
    </view>
    

这两种方式都会触犯分享, 并调用 Page.onShareAppMessage 方法


分享传递参数

  1. onShareAppMessage 定义相关参数

      onShareAppMessage: function (options) {
        if (options.from === 'button') {
          // 来自 页面自定义按钮, 可以获取到按钮相关参数
          console.log(options.target)
        }
        return {
          title: '--- aaa: 自定义转发标题',
          imageUrl: 'http://p7kuppz6y.bkt.clouddn.com/testShare.jpg', // 分享图(比例是 5:4), 不定义的话默认使用当前界面的截图.
          path: '/pages/show/show?id=123&name=hello', // 分享出去后, 别人点击后跳转的页面及相关参数传递过去. 这里只能使用绝对路径.
          success: (res) => {
            console.log("--- success, res:", res)
          },
          fail: (res) => {
            console.log("--- fail, res:", res)
          }
        }
      },
    
  2. 测试

    a用 户分享给 b用户, b用户点击后会 直接跳转到 /pages/show/show 界面 并在 Page.onLoad 方法中可以获取到参数 idname

    onLoad: function (options) {
        gLog("--- show onLoad", options)
    },
    

猜你喜欢

转载自blog.csdn.net/yangxuan0261/article/details/83505437