uni-app vue3小程序中使用onShareAppMessage分享参数为空

uni-app vue3小程序中使用onShareAppMessage分享参数为空

项目 信息
产品分类 uniapp/小程序/微信
PC开发环境操作系统 Windows
PC开发环境操作系统版本号 Windows 10 专业版
HBuilderX类型 正式
HBuilderX版本号 3.8.12
第三方开发者工具版本号 1.06.2303220
基础库版本号 3.0.0
项目创建方式 HBuilderX

示例代码:

<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad(e) {
console.log(e)
},
methods: {
onShareAppMessage() {
return {
title: '转发给好友',
path: '/pages/index/index?id=123'
}
},
onShareTimeline(){
return {
title:"参数",
query:"id=123"
}
}
}
}
</script>

操作步骤:

用hbuider创建vue2和vue3,把代码示例放进去,vue2可以成功得到分享的参数,但是vue3分享参数获取是为空

预期结果:

{id:123}

实际结果:

{}

bug描述:

onShareTimeline,onShareAppMessage,这两个在vue3里都没有分享参数,在点击右上角胶囊里的分享给好友及分享到朋友圈,携带参数分享为空,但是能成功分享出去


更多关于uni-app vue3小程序中使用onShareAppMessage分享参数为空的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

已解决,我的问题,vue3使用是 export default { data() { return { title: ‘Hello’ } }, onLoad(e) { console.log(e) }, onShareAppMessage() { return { title: ‘转发给好友’, path: ‘/pages/index/index?id=122131233’ } }, onShareTimeline(){ return { title:“参数”, query:“id=123” } } methods: {
}
}

更多关于uni-app vue3小程序中使用onShareAppMessage分享参数为空的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个已知的uni-app在Vue3模式下的小程序分享参数问题。以下是关键点分析:

  1. 问题原因:
  • Vue3版本中,分享回调函数的参数传递机制与Vue2不同
  • 在Vue3中,直接返回的path和query可能不会被正确解析
  1. 解决方案: 对于onShareAppMessage,可以这样修改:
onShareAppMessage() {
  return {
    title: '转发给好友',
    path: `/pages/index/index?id=123`
  }
}

对于onShareTimeline:

onShareTimeline() {
  return {
    title: "参数",
    query: `id=123`
  }
}
回到顶部