微信小程序——邀请好友和分享到朋友圈
邀请好友
代码块
wxml: 注:分享必须用button,不能用超链接形式或者图片 button style='opacity: 0;' bindtap='onShareAppMessage' open-type="share"邀请好友/buttonjs:onShareAppMessage: function (ops) { if (ops.from === 'button') { // 来自页面内转发按钮 console.log(ops.target) } return { title: '快来.....啦', imageUrl:'http://xxxx',//图片地址 path:'/pages/index/index?jump=123',// 用户点击首先进入的当前页面 success: function (res) { // 转发成功 console.log("转发成功:"); }, fail: function (res) { // 转发失败 console.log("转发失败:"); } } },转发的页面到好友只是分享的当前页,一般性的会跳转到小程序的主页面,所以。。。
可以直接在onLoad里面写,也可以onLoad和onShow搭配使用/** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log("options============" + options) var that = this that.setData({ jump : options.jump, }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { var jump1 = this.data.jump; if (jump1 == 123) { wx.reLaunch({ url: '/pages/index/login' //跳转页面,reLaunch(没有记忆前一页) }) } }, 分享朋友圈
微信小程序不允许直接分享朋友圈,此方法是通过自己保存分享内容到朋友圈
代码块
wxml: button style='opacity: 0;' bindtap='createNewImg'分享图片/buttonjs:createNewImg: function () { wx.previewImage({ current: 'http://xxx', // 当前显示图片的http链接 urls: ['http://xxx'] // 需要预览的图片http链接列表,数组形式 }) },















