一、前置问题
- uni-app的小程序页面默认是不可分享的,点击页面右上角按钮进行分享时会提示:“当前页面不可转发/当前页面不可分享”

二、解决方法
- 打开项目的manifest.json文件,在“App模块配置”项的“Share(分享)”下,勾选“微信分享”:

- 在代码中开启分享转发按钮,再次打开小程序页面,就可以正常分享了。
<script>
export default {
created() {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
});
},
data() {
return {
title:'标题',
thumb:'https://img.demo.com/static/images/1.jpg'
}
},
onShareAppMessage(res) {
return {
title: this.title,
imageUrl: this.thumb,
}
},
onShareTimeline(res) {
return {
title: this.title,
imageUrl: this.thumb,
}
},
methods: {
}
}
</script>