x嘻嘻嘻 好久沒有寫了
因為小程序不能直接分享到朋友圈(我是沒找到怎么直接分享過去的方法)、
然后我就想到了一個方法,寫一個分享按鈕,然后點擊后出現一張圖,用戶保存這張圖片到手機上在發朋友圈
雖然這個用戶步驟有點繁瑣,但是這是我想到的唯一方法了
畢竟腦洞不大啊~
效果圖 ⬇️⬇️⬇️

好了 言歸正傳 開始上代碼啦
解決方法 ⬇️⬇️⬇️
// .wxml 這個是點擊分享按鈕后出現的頁面
<view class='aa' wx:if="{{share}}" > // wx:if="{{share}}" 這個控制出現頁面展示/隱藏 <image mode='widthFix' class="sharepicture" src='這個地方是圖片的地址' ></image> //這個是展示圖地址 <image mode='widthFix' class="shutdown" src='這個是關閉按鈕圖片的地址' bindtap='shutdown'></image> //這個是關閉按鈕 <view bindtap='clickshare' class='modemeg'>保存圖片</view> //這個是點擊保存圖片按鈕 </view>
data:{ share: false, }, //點擊關閉分享 Shutdown: function(e){ console.log("E....",e) this.setData({ share: false }) }, //保存圖片按鈕 clickshare: function(){ var imgSrc = "https://www.liao-shu.com/ptcent_file_upload/emotion/share.png" wx.downloadFile({ url: imgSrc, success: function (res) { console.log(res);//圖片保存到本地 wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: function (data) { console.log(data); }, fail: function (err) { console.log(err); if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") { wx.openSetting({ success(settingdata) { console.log(settingdata) if (settingdata.authSetting['scope.writePhotosAlbum']) { console.log('獲取權限成功,給出再次點擊圖片保存到相冊的提示。') } else { console.log('獲取權限失敗,給出不給權限就無法正常使用的提示') } } }) } } }) } }) }
