1. 程式人生 > 其它 >微信小程式分享好友和朋友圈

微信小程式分享好友和朋友圈

注意:安卓支援分享好友和朋友圈,ios不支援分享朋友圈

在需要分享的頁面js的onLoad中

    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline']       // 分享好友、朋友圈
    }) 
/**
   * 使用者點選右上角分享
   */
  onShareAppMessage (res) {
    return {
      title: '自定義,一般寫小程式的名字',
      path: 'pages/index/index',
      // imageUrl:'這個是顯示的圖片,不寫就預設當前頁面的截圖',
success: function (shareTickets) { console.info(shareTickets + '成功'); // 轉發成功 }, fail: function (res) { console.log(res + '失敗'); // 轉發失敗 }, complete:function(res){ // 不管成功失敗都會執行 } } },

如果不想要頁面分享,在不需要分享的頁面js的onLoad中

 wx.hideShareMenu({
      menus: [
'shareAppMessage', 'shareTimeline'] })
設定分享:
wx.showShareMenu()
禁止分享 wx.hideShareMenu()