h5页面调用小程序分享方法

小程序端

<web-view src="{{path}}" bindmessage="handleWebviewMessage"></web-view>
data: {
    path: '',
    shareOptionsObj: {},
  },
  onLoad(options: { webview: string }) {
    this.setData({
      path: decodeURIComponent(options.webview)
    })
  },
  onShareAppMessage() {
    const _this = this
    return _this.data.shareOptionsObj
  },
  handleWebviewMessage(e: WechatMiniprogram.CustomEvent) {
    const obj = e.detail.data[e.detail.data.length - 1]
    if (obj.type === 'share') {
      this.setData({
        shareOptionsObj: e.detail.data[e.detail.data.length - 1].config,
      })
    }
  }

H5端

<div class="page-transfer-page-container">
    <div @click="onShare" class="btn-share">国民家</div>
</div>
import wx from 'weixin-js-sdk' // 引入微信sdk依赖 版本: "weixin-js-sdk": "^1.6.0"
methods: {
    onShare() {
      wx.miniProgram.postMessage({
        data: {
          type: 'share',
          config: {
            title: '国民家',
            path: `/pages/webview/index?webview=${encodeURIComponent(
              'https://ai.insurtechbank.net/pa-health-ui/#/transferPage',
            )}`,
            imageUrl:
              'https://wallet-minio.lianft.com/picc/miniapp/share/share.png',
          },
        },
      })
    },
  },
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值