uni-app分享小程序页面

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

配置

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

在代码中开启分享转发按钮

<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>

再次打开小程序页面,会发现已经可以分享了。

猜你喜欢

转载自blog.csdn.net/watson2017/article/details/130238223