share.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import wx from 'weixin-js-sdk'
  2. const url = (window.location.href.split('index.html')[0])+'index.html'
  3. export const shareConfig = (shareData, vm) => {
  4. vm.$u.api.wxInfo.getWxShareData({
  5. url
  6. }).then(res => {
  7. wx.config({
  8. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  9. appId: res.appId, // 必填,公众号的唯一标识
  10. timestamp: res.timestamp, // 必填,生成签名的时间戳
  11. nonceStr: res.nonceStr, // 必填,生成签名的随机串
  12. signature: res.signature, // 必填,签名
  13. jsApiList: [
  14. "updateAppMessageShareData",
  15. "updateTimelineShareData",
  16. 'wx-open-launch-weapp',
  17. ],
  18. openTagList: ['wx-open-launch-weapp']
  19. });
  20. //分享到好友
  21. wx.ready(function() {
  22. wx.updateAppMessageShareData({
  23. ...shareData,
  24. success: function() {
  25. console.log("配置成功1");
  26. }
  27. })
  28. });
  29. //分享到朋友圈
  30. wx.ready(function() {
  31. wx.updateTimelineShareData({
  32. ...shareData,
  33. success: function() {
  34. console.log("配置成功2");
  35. },
  36. })
  37. });
  38. wx.error(function(res) {
  39. console.log(res);
  40. });
  41. })
  42. }