微信小程序怎么通过方法去手动调用分享朋友圈或者分享到微信?

微信小程序怎么通过方法去手动调用分享朋友圈或者分享到微信?

而不是通过直接在右上角点击三个点,点击三个点我知道只要在page里面的对应的onShareAppMessage和onShareTimeline配置对应的方法就好了,

我的意思是如何让用户点击页面的按钮的时候让他手动拉起来弹窗,像点击右上角三个点一样

阅读 2.5k
2 个回答

button 设置 open-type="share"

使用这个

https://developers.weixin.qq.com/miniprogram/dev/reference/ap...

监听用户点击页面内转发按钮(button 组件 open-type="share")或右上角菜单“转发”按钮的行为,并自定义转发内容。 右上角菜单“转发”按钮的行为

Page({ //右上角菜单“转发”按钮的行为
  onShareAppMessage() {
    const promise = new Promise(resolve => {
      setTimeout(() => {
        resolve({
          title: '自定义转发标题'
        })
      }, 2000)
    })
    return {
      title: '自定义转发标题',
      path: '/page/user?id=123',
      promise 
    }
  }
})

自定义按钮点击行为

//wxml
<button style="padding: 0;margin: 0;width:100%;" class='button' open-type="share">
  <text>分享小程序</text>
</button>
//javascript
onShareAppMessage () { //分享小程序页面
    return {
      title:'自定义标题',
      path: 'page/xxx/xx/xxx/?id=xxx&name=xxxx', //传入id参数可以渲染商品详情类的页面
      imageUrl:"../../images/headimg/back.jpeg", // 自定义分享时好友看到的图片
      success (res) { //成功时回调
        console.log('成功', res)
      }
    }
  },
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题