uni-app 第三方應用中調起微信分享


最近做項目的時候遇到一個問題

在APP中的某個單獨的小項目中使用uni-app寫的項目調起微信分享

單獨引入jweixin-1.6.0.js在需要分享的頁面中時,

頁面會報錯,導致原有的數據都沒有展示出來;

 

可以使用第三地方組件

npm install jweixin-module --save

安裝微信分享模塊

安裝完成后你會得到一個jweixin-module 的包,

然后

import wx from "@/jweixin-module/jweixin-module/lib/index.js"

在頁面中引入模塊

wxShare(config, news, users){

  var _this = this;
  //微信分享
  wx.config({
    appId: config.appId,
    timestamp: config.timestamp,
    nonceStr: config.nonceStr,
    signature: config.signature,
    debug: config.debug,
    jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "chooseImage",
    "uploadImage", "hideMenuItems", "closeWindow"
    ] // 所有要調用的 API 都要加到這個列表中
  });
  wx.ready(function() {
  // 在這里調用 API
  wx.hideMenuItems({
    menuList: ['menuItem:copyUrl', 'menuItem:favorite', 'menuItem:originPage', 'menuItem:openWithQQBrowser','menuItem:openWithSafari', 'menuItem:share:email', 'menuItem:share:qq', 'menuItem:share:weiboApp','menuItem:share:QZone'
    ] // 要隱藏的菜單項,只能隱藏“傳播類”和“保護類”按鈕,所有menu項見附錄3,分享朋友:'menuItem:share:appMessage',分享朋友圈:'menuItem:share:timeline'
  });

  wx.onMenuShareTimeline({ //分享到朋友圈
    *******
  });

  wx.onMenuShareAppMessage({ //分享給朋友
    ****
  });
  });
;

 

注意:

wx.config不要放到wx.ready方法里面


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM