【报Bug】Vue3 在hook中使用与onLoad同级的页面生命周期事件在微信小程序中不生效,例如 onShareAppMessage、onShareTimeline、onPageScroll等
- 发布:2023-01-10 14:51
- 更新:2023-01-11 17:07
- 阅读:777
【报Bug】Vue3 在hook中使用与onLoad同级的页面生命周期事件在微信小程序中不生效,例如 onShareAppMessage、onShareTimeline、onPageScroll等
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 10
第三方开发者工具版本号: 3.0.0-alpha-3060220220914001
基础库版本号: 3.0.0-alpha-3060220220914001
项目创建方式: CLI
CLI版本号: 3.0.0-alpha-3060220220914001
示例代码:
操作步骤:
export function useShare({ title, path, imageUrl, query = {} }: CustomShareAppMessage) {
const { routerAlias } = useNavigate();
onLoad(() => {
const pageList = getCurrentPages();
const currentPage = pageList[pageList.length - 1];
console.log(currentPage);
uni.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
});
});
onShareAppMessage(() => {
const pageList = getCurrentPages();
const currentPage = pageList[pageList.length - 1].$page.fullPath;
const sharePath = serializeUrl(routerAlias.HOME_PAGE, {
pagePath: currentPage,
type: 'share'
});
return {
title: title || '两点文化,随身书法课堂,让你轻松写好字。',
path: sharePath,
imageUrl: imageUrl ? imageUrl : resolveStaticUrl('share.jpg')
};
});
onShareTimeline(() => {
return {
title: title || '两点文化,随身书法课堂,让你轻松写好字。',
query,
imageUrl: imageUrl ? imageUrl : resolveStaticUrl('share.jpg')
};
});
}
export function useShare({ title, path, imageUrl, query = {} }: CustomShareAppMessage) {
const { routerAlias } = useNavigate();
onLoad(() => {
const pageList = getCurrentPages();
const currentPage = pageList[pageList.length - 1];
console.log(currentPage);
uni.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
});
});
onShareAppMessage(() => {
const pageList = getCurrentPages();
const currentPage = pageList[pageList.length - 1].$page.fullPath;
const sharePath = serializeUrl(routerAlias.HOME_PAGE, {
pagePath: currentPage,
type: 'share'
});
return {
title: title || '两点文化,随身书法课堂,让你轻松写好字。',
path: sharePath,
imageUrl: imageUrl ? imageUrl : resolveStaticUrl('share.jpg')
};
});
onShareTimeline(() => {
return {
title: title || '两点文化,随身书法课堂,让你轻松写好字。',
query,
imageUrl: imageUrl ? imageUrl : resolveStaticUrl('share.jpg')
};
});
}
预期结果:
分享应该以 return内容为主
分享应该以 return内容为主
实际结果:
onLoad 生效 onShareAppMessage onShareTimeline不生效
onLoad 生效 onShareAppMessage onShareTimeline不生效
小小菜76055421
大佬,看下这个问题,也是3.6.16出现的 https://ask.dcloud.net.cn/question/161232
2023-01-11 10:37