uni-app开发微信小程序-分享小程序页面

488 阅读1分钟

一、前置问题

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

image.png

二、解决方法

  • 打开项目的manifest.json文件,在“App模块配置”项的“Share(分享)”下,勾选“微信分享”:

image.png

  • 在代码中开启分享转发按钮,再次打开小程序页面,就可以正常分享了。
<script>
	export default {
		created() {
			//#ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			//#endif
		},
		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>