Skip to content

onShareTimeline(): ICustomTimelineContent | void 没有支持promise参数 #373

@Darley-Wey

Description

@Darley-Wey

onShareTimeline()
基础库 2.11.3 开始支持,低版本需做兼容处理

详见分享到朋友圈

监听右上角菜单“分享到朋友圈”按钮的行为,并自定义分享内容。

注意:只有定义了此事件处理函数,右上角菜单才会显示“分享到朋友圈”按钮

自定义转发内容

事件处理函数返回一个 Object,用于自定义分享内容,不支持自定义页面路径,返回内容如下:

字段 说明 默认值 最低版本
title 自定义标题,即朋友圈列表页上显示的标题 当前小程序名称
query 自定义页面路径中携带的参数,如 path?a=1&b=2 的 “?” 后面部分 当前页面路径携带的参数
imageUrl 自定义图片路径,可以是本地文件或者网络图片。支持 PNG 及 JPG,显示图片长宽比是 1:1。 默认使用小程序 Logo
promise 如果该参数存在,则以 resolve 结果为准,如果三秒内不 resolve,分享会使用上面传入的默认参数 3.12.0
示例代码

Page({
onShareTimeline() {
const promise = new Promise(resolve => {
setTimeout(() => {
resolve({
title: '自定义转发标题'
})
}, 2000)
})
return {
title: '自定义转发标题',
query: 'id=123',
imageUrl: '/images/share.png',
promise
}
}
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions