微信小程序--分享报错(thirdScriptError Cannot read property \'from\' of undefined;at pages/index/index page onShareAppMessage function TypeError: Cannot read property \'from\' of undefined)
分享功能:
onShareAppMessage: function (res) {
if (res.from === \'button\') {
// 来自页面内转发按钮
console.log(res.target)
}
return {
title: \'首页\',
path: \'pages/index/index\',
imageUrl: "../../img/share.png"
}
}
今天在开发小程序分享功能时,报错如下。
thirdScriptError
Cannot read property \'from\' of undefined;at pages/index/index page onShareAppMessage function
TypeError: Cannot read property \'from\' of undefined
后来查看微信开发社区发现:
10月10日起新提交发布的版本,不再支持分享回调参数 success 、fail 、complete,即用户从小程序/小游戏中分享消息给好友时,开发者将无法获知用户是否分享完成,也无法在分享后立即获得分享成功后的回调参数shareTicket。该调整可以在基础库 2.3.0及以上版本体验。
由于不再支持分享回调参数,所以报错。报如下代码删除即可
if (res.from === \'button\') {
// 来自页面内转发按钮
console.log(res.target)
}