微信小程序的分享页图片如何自定义呢?

1.先要把open-type设置成share

<button wx:if="{{shareMid == undefined}}" open-type="share" class="save-order">分享</button>

注意:右上角也可进行分享

2.触发 onShareAppMessage 方法

//分享 onShareAppMessage:function () {

                             return {

                                title: this.data.rows.keyword,

                                desc: this.data.rows.linename,

                                path: '/pages/home/home?id='+ this.data.pageId,表示用户点击分享页跳转到的位置

                                imgUrl:自定义图片的地址

                             

} },


 

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
在小程序中,我们可以通过在页面中定义 `onShareAppMessage` 方法来自定义分享内容。 具体步骤如下: 1. 在需要分享的页面的 `.js` 文件中,定义 `onShareAppMessage` 方法: ```javascript Page({ onShareAppMessage: function () { return { title: '分享标题', path: '/pages/index/index', imageUrl: 'http://example.com/share.jpg' } } }) ``` 2. 在 `onShareAppMessage` 方法中,我们可以返回一个对象,该对象中包含以下参数: - `title`:分享标题,必填项。 - `path`:分享路径,必填项。 - `imageUrl`:分享图片地址,可选项。 3. 在 `onShareAppMessage` 方法中,我们可以通过调用微信提供的 API 获取当前页面的一些信息,例如页面标题、路径等。例如: ```javascript Page({ onShareAppMessage: function () { const title = this.data.title // 页面标题 const path = '/pages/index/index' // 页面路径 const imageUrl = 'http://example.com/share.jpg' // 分享图片地址 return { title: title, path: path, imageUrl: imageUrl } } }) ``` 4. 在 `.wxml` 文件中,我们可以添加一个分享按钮,并将其绑定到 `onShareAppMessage` 方法: ```html <button class="share-btn" bindtap="onShareTap">分享给好友</button> ``` ```javascript Page({ onShareTap: function () { wx.showShareMenu({ withShareTicket: true }) }, onShareAppMessage: function () { // ... } }) ``` 以上就是在微信小程序中通过 `onShareAppMessage` 方法自定义分享内容的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值