微信小程序服务器转发,微信小程序之分享或转发功能(自定义button样式)

小程序页面内发起转发

通过给 button 组件设置属性open-type="share",可以在用户点击按钮后触发 Page.onShareAppMessage 事件,如果当前页面没有定义此事件,则点击后无效果。相关组件:button

wxml:

分享

wxss:

.share {

height: 120rpx;

120rpx;

position: fixed;

bottom: 170rpx;

right: 30rpx;

display: flex;

flex-direction: column;

align-items: center;

justify-content: center;

font-size: 24rpx;

background: rgba(0, 0, 0, .6);

border-radius: 50%;

z-index: 10;

}

.share image {

height: 70rpx;

70rpx;

}

.share text {

color: #fff;

}

.share button {

position: absolute;

height: 100%;

100%;

opacity: 0.1;

z-index: 99;

}

js:

onShareAppMessage(res) {

let id = wx.getStorageSync('shareId') // 分享产品的Id

if (res.from === 'button') {

// 来自页面内转发按钮

console.log(res.target)

}

return {

title: '转发标题',

path: `pages/detail/detail?id=${id}` // 分享后打开的页面

}

},

按钮样式如图:

1e8217d859a7a6250cdfde3ade06aaa2.png

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值