微信小程序分享功能的实现方法有两种

官方设定5:4 小程序分享尺寸太大,尺寸500px400px(宽高)

在page.js中实现onShareAppMessage,便可在小程序右上角选择分享该页面

onShareAppMessage: function () {
 return {
  title: '弹出分享时显示的分享标题',
  desc: '分享页面的内容',
  path: '/page/user?id=123' // 路径,传递参数到指定页面。
 }
}

自定义按钮实现分享,在page中添加一个带有open-type='share’的button标签()。点击该按钮后,即会自动触发已经在page.js中定义好的onShareAppMessage方法,实现分享功能。

<button open-type='share'>分享</button>

获取分享传递的参数
path属性指向的是user页面,并附带id=123的参数。我们只需在user.js的onLoad函数中,通过options查看传递过来的参数:

// user.js
Page({
 onLoad: function(options) {
  console.log(options);
 }
})

猜你喜欢

转载自blog.csdn.net/qq_37194189/article/details/130018565