微信小程序动态设置分享踩坑
发布: 2020-02-28 11:10:53标签: 小程序
一、错误操作:通过touchStart事件动态设置分享内容
错误逻辑描述:
- 通过open-type的button绑定touchstart修改分享内容
- 然后在onShareAppMessage获取修改过之后的分享内容
上述方式部分android会有兼容问题
二、正确操作:通过在button绑定属性来动态获取分享的数据
01<button open-type="share" data-title="分享标题一">分享</button>
复制代码01onShareAppMessage(res) {02 if (res.from === "button") { 03 const {title} = res.target.dataset04 return {title}05 } else {06 return {title: '默认分享标题'}07 }08}
复制代码