公众号微信分享如何实现

vue项目
要做个微信分享的功能
网上各种搜,写出代码如下,但是点击并没任何反应,求大神指导

<template>
    <button @click="share">分享</button>
</template>
<script>
import wx from 'weixin-js-sdk'
activated () {
    this.initWxConfig()
},
methods: {
share () {
    console.log('share')
      var shareData = {
        // imgUrl: 'http://yzdw.dream-world.com.cn/ftp/static/u/cms/www/201810/111529310qzz.jpg',
        imgUrl: 'http://yzdw.dream-world.com.cn/ftp/static/u/cms/www/images/f6081d232c67e61700a3d0b0a5a7c82.jpg',
        link: location.href.split('#')[0],
        desc: '分享描述',
        title: '分享标题',
        type: 'link',
        success: function(res){
          console.log(res, '分享好了')
          this.$toast('success')
        }
      }
      wx.ready(res => {
        console.log(res, '---wx ready---')
        console.log(wx.onMenuShareAppMessage, 'onMenusharemssage')
        console.log(shareData, 'share data')
        // wx.updateAppMessageShareData(shareData)
        wx.onMenuShareAppMessage(shareData)
      })
      wx.error(function(err){
        console.log(err, '失败信息')
      })
    },
    initWxConfig() {
        var ua = navigator.userAgent.toLowerCase()
        var isWeixin = ua.indexOf('micromessenger') !== -1
        if (isWeixin) {
        // 这里是获取签名 appid等数据
          axios.get(apis.wechatShare, {
            params: {
              url: location.href.split('#')[0]
            }
          }).then(res => {
            const {body, code} = res.data
            if (code === '200') {
              wx.config({
                debug: false,
                appId: body.appId,
                nonceStr: body.noncestr,
                signature: body.signature,
                timestamp: body.timestamp,
                jsApiList: [
                  // 'updateAppMessageShareData'
                  'onMenuShareAppMessage'
                ]
              })
            }
          })
        } else {
          this.$toast('请在微信中打开该网站, 否则无法正常使用')
        }
    }
}
</script>

图片描述

wx.config end 显示errMsg: "config:ok"就是配置正确了吗
但为什么调用share,并没有出现选择好友的界面,请大神指导

阅读 1.5k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题