微信小程序-自定義分享


wxml

<view class="view">
<image class="cover-9" src="{{img}}" bindtap="img"></image>
<view class="window-1">
<button type="default" id="open" bindtap="showShareMenu">開啟分享</button>
<button type="warn" id="close" bindtap="hideShareMenu">關閉分享</button>
</view>
<button type="primary" open-type="share" data-name="pageShare" id="share">點擊分享</button>
</view>
 
js
 
let app = getApp();
Page({
data: {
img: "/images/1.png"
},
onLoad() {
},
showShareMenu() {
wx.showShareMenu();
console.log("顯示了當前頁面的轉發按鈕");
},
hideShareMenu() {
wx.hideShareMenu();
console.log("隱藏了當前頁面的轉發按鈕");
},
onShareAppMessage: (res) => {
if (res.from === 'button') {
console.log("來自頁面內轉發按鈕");
console.log(res.target);
}
else {
console.log("來自右上角轉發菜單")
}
return {
title: '妹子圖片',
path: '/pages/share/share?id=123',
imageUrl: "/images/1.jpg",
success: (res) => {
console.log("轉發成功", res);
},
fail: (res) => {
console.log("轉發失敗", res);
}
}
}
})
 
 
wxss
 
page{
height: 100%;
}
.view{
width: 100%;
height: 100%;
}
.window-1{
display: flex;
flex-direction: row;
margin: 20rpx 0;
}
.cover-9{
width: 688rpx;
height: 75%;
margin: 0 30rpx;
border:2rpx solid;
border-radius:5px;
}
button{
margin: 0 10rpx;
width: 100%;
}
#share{
width: 730rpx;
}


免責聲明!

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



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