Wechat applet sharing and forwarding events

"Sharing and forwarding" function of wechat applet
1. On page custom sharing
2. "..." in the upper right corner of the page Sharing behavior

When the event "onShareAppMessage" is not added to the page js, the upper right corner "..." No forward events will occur.
If there is an event, but the event content is not defined, the forwarded card is the screen capture information of the current page.

1) Use "..." in the top right corner of the default page Sharing events

Page({
  onShareAppMessage: function (res) {
    return {
      title: 'This is the default forwarding',
      path: '/pages/index/index?id=123',
      imageUrl: '****.png'//This is a shared picture
    }
  }
})

2) When there is a custom "share" button on the page

 <!-- index.wxml Page -- >
    <button class="share_icon" open-type = "share">
        Custom share button
    </button>
/*index.js*/
Page({
  onShareAppMessage: function (res) {
    let title,imageUrl;
    if (res.from === 'button') {
      // From on page forward button
      title= 'This is a custom sharing event for the page~';
      imageUrl='***.png';
    }
    if(res.from ==='menu'){
      title= 'This is the sharing event in the upper right corner of the page~';
      imageUrl='***.png';
    }
    return {
      title: title,
      imageUrl: imageUrl,//This is a shared picture
      path: '/page/user?id=123',
    }
  }
})

3) When there are multiple custom share buttons on the page

 < button open type = < share 'id = share1 "> this first share button < / button >
    < button open type = < share 'id = share2 "> this first share button < / button >

/*index.js*/
Page({
  onShareAppMessage: function (res) {
    let title,imageUrl;
    console.log(res.target);
    if (res.from === 'button' && res.target.id == 'share1') {
      title= 'This is a custom share button on the page share1 Sharing events for~';
      imageUrl='***.png';
    }
    if (res.from === 'button' && res.target.id == 'share2') {
      title= 'This is a custom share button on the page share2 Sharing events for~';
      imageUrl='***.png';
    }
    if(res.from ==='menu'){
      title= 'This is the sharing event in the upper right corner of the page~';
      imageUrl='***.png';
    }
    return {
      title: title,
      imageUrl: imageUrl,//This is a shared picture
      path: '/page/user?id=123',
    }
  }
})

Tags: Front-end

Posted on Tue, 30 Jun 2020 01:32:51 -0400 by Edward