dcloudio / dcloudio/uni-app

微信小程序接口 Page.onShareTimeline Typescript interface 定义错误

Open
#2,296 0 comments 0 reactions 0 assignees View on GitHub
mp-weixin 提供了复现方案
Dominant language
JavaScript
Stars
41.6k
Forks
3.7k
Avg merge
7h 6m
Merged PRs (30d)
6

Description

**问题描述**
[问题描述:尽可能简洁清晰地把问题描述清楚]
typescript 环境 onShareTimeline 分享到朋友圈 定义参数无效

**复现步骤**

新建一个页面 定义分享到朋友圈相关函数
```vue


朋友圈
normal

import Vue from "vue";

export default Vue.extend({
name: "Test",
data() {
return {
timeline: 0
}
},
onLoad(options: any) {
const { timeline = 0 } = options
this.timeline = +timeline
},
onShareAppMessage() {
return {
title: 'aaaa',
path: '/pages/index/index?a=3'
}
},
onShareTimeline() {
return {
title: 'bbbb',
path: 'a=3&timeline=1'
}
}
});

```
**预期结果**
点击小程序分享到朋友圈按钮
页面出现 “朋友圈”
**实际结果**
出现 “normal”

**系统信息:**
- 发行平台: 微信小程序
- 操作系统: Android 10.0
- uni-app版本:^2.0.0-29320201014001
- 设备信息 XiaoMi Mix3

**补充信息**

查看小程序官网文档
[onShareTimeline](https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareTimeline)

定义的参数字段应为query

代码改为
```vue
onShareTimeline() {
return {
title: 'bbbb',
query: 'a=3&timeline=1'
}
}
```
分享到朋友圈 出现期望结果

@types/uni-app/page.d.ts 中定义的的 ShareTimelineContent 需要更改为如下 或者 sfc.d.ts 添加下面的代码
```ts
declare namespace Page {
interface ShareTimelineContent {
/**
* 自定义标题。默认值:当前小程序名称
*/
title?: string;
/**
* 自定义页面路径中携带的参数
*/

// path?: string;
// 这里应该改成query 字段
query?: string
/**
* 自定义图片路径,可以是本地文件或者网络图片。支持 PNG 及 JPG,显示图片长宽比是 1:1。
*/
imageUrl?: string;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.