在頁面內(nèi)使用了onShareTimeline
方法蜗搔,右上角內(nèi)也出現(xiàn)了分享朋友圈的按鈕劲藐,但是頁面內(nèi)的分享自定義內(nèi)容卻沒有成功設(shè)置,分享出去還是默認的小程序名稱樟凄。
原因:taro@3.0.3內(nèi)缺失相應(yīng)的類型定義聘芜,在設(shè)置分享朋友圈自定義內(nèi)容時導(dǎo)致自定義內(nèi)容失效。
#7055
解決:
方法一: 升級至3.0.3以上缝龄;
方法二:在global.d.ts
內(nèi)添加缺失的類型定義汰现,并在需要分享朋友圈的頁面配置文件內(nèi)添加enableShareTimeline: true
。
// global.d.ts
declare module '*.json' {
const value: any
export default value
}
declare module '@tarojs/taro' {
interface PageConfig {
/**
* 是否啟用分享給好友叔壤。
*
* @default false
*/
enableShareAppMessage?: boolean
/**
* 是否啟用分享到朋友圈瞎饲。
*
* @default false
*/
enableShareTimeline?: boolean
}
}
// index.config.js
export default {
enableShareAppMessage: true,
enableShareTimeline: true
}
參考#7055: https://github.com/NervJS/taro/pull/7055
注:
設(shè)置自定義分享時query需要采用object的形式。
// 分享朋友圈
onShareTimeline(res) {
let { detail, user_info, is_myRep, work_pos } = this.state;
return {
// 這是我創(chuàng)作的第3幅作品炼绘,獲得了5星評價嗅战,快來給我點贊吧
title: `這是我創(chuàng)作的第3幅作品,獲得了5星評價,快來給我點贊吧`,
// query: `is_fromShare=true&id=${detail.id}`,
query: {is_fromShare: true, id: detail.id},
imageUrl: detail.work_img
};
}
效果:
分享朋友圈效果