Today simply WeChat under small forward capability, why want to say the simple, because main is forwarded to friends or groups, and there’s a share to friends, this is more complicated, first a little bit revealed, share to the circle of friends are mainly two kinds of methods, one is the background to produce posters figure, One is that the front end generates posters through canvas. We’ll talk more about it later when we have a chance. Okay, let’s get back to our forwarding friends.
OnShareAppMessage (Options)
Define the onShareAppMessage function in the Page to set the forwarding information for that Page.
- Only if this event handler is defined will the forward button appear in the upper-right menu
- Called when the user clicks the forward button
- This event requires a return Object, which is used to customize the forwarding content
Options Parameter Description
User-defined forwarding fields
There is also a value called shareTickets, which is returned by successful forwarding and is an array, where each item is a shareTicket corresponding to a forwarding object
So much for the API, then the implementation of forwarding
Look at the picture first:
The first step is to configure wx.showShareMenu in onLoad
OnLoad: function (e) {wx.showShareMenu({withShareTicket: true}); },
Then configure onShareAppMessage
/* forward */ onShareAppMessage: Function (ops) {if (ops. From === 'button') {console.log(ops. Target)} return {title: 'dom', path: 'pages/index/index', success: function (res) {console.log(" error :" + json.stringify (res)); var shareTickets = res.shareTickets; // if (shareTickets.length == 0) { // return false; Wx. getShareInfo({// shareTicket: shareTickets[0], // success: function (res) { // console.log(res) // } // }) }, fail: Function (res) {// failed to forward console.log(" failed to forward :" + json.stringify (res)); }}},
Let me explain that wx.getShareInfo is available to get forward details
The complete JS code is
Const app = getApp() Page({data: {motto: 'Hello World',}, onLoad: Function (e) {wx.showShareMenu({withShareTicket: true}); }, /* forward */ onShareAppMessage: Function (ops) {if (ops. From === 'button') {console.log(ops. Target)} return {title: 'dom', path: 'pages/index/index', success: function (res) {console.log(" error :" + json.stringify (res)); var shareTickets = res.shareTickets; // if (shareTickets.length == 0) { // return false; Wx. getShareInfo({// shareTicket: shareTickets[0], // success: function (res) { // console.log(res) // } // }) }, fail: Function (res) {// failed to forward console.log(" failed to forward :" + json.stringify (res)); }}}})
Those of you who are smart should know that the WXML code is next
<view class="container"> <view class="userinfo"> <button open-type="share"> </button> </view> <view class="usermotto"> <text class="user-motto">{{motto}}</text> </view> </view>
As a reminder, button must set open-type=”share” otherwise it will not work.
Github.com/Mr-MengBo/w…