WeChat ミニプログラム「シェア、フォワード」イベント

WeChat ミニ プログラムの「共有、転送」機能
1. ページ内のカスタム共有
2. ページ右上隅の「...」共有動作

ページjsにイベント「onShareAppMessage」が追加されていない場合、右上の「...」イベントは表示されません。
イベントが存在するが、イベントの内容が定義されていない場合、転送されるカードは現在のページのスクリーンショット情報です。

1) デフォルトページの右上隅にある「...」を使用してイベントを共有します

Page({
    
    
  onShareAppMessage: function (res) {
    
    
    return {
    
    
      title: '这是默认转发',
      path: '/pages/index/index?id=123',
      imageUrl: '****.png'//这个是分享的图片
    }
  }
})

2) ページ上にカスタムの「共有」ボタンがある場合

    <!--index.wxml页面-->
    <button class="share_icon" open-type = "share">
        自定义分享按钮
    </button>
/*index.js*/
Page({
    
    
  onShareAppMessage: function (res) {
    
    
	let title,imageUrl;
    if (res.from === 'button') {
    
    
      // 来自页面内转发按钮
      title= ‘这个是页面自定义的分享事件~’;
      imageUrl='***.png';
    }
    if(res.from ==='menu'){
    
    
	  title= ‘这个是页面右上角的分享事件~’;
	  imageUrl='***.png';
    }
    return {
    
    
      title: title,
      imageUrl: imageUrl,//这个是分享的图片
      path: '/page/user?id=123'}
  }
})

3) ページ上に複数のカスタム共有ボタンがある場合

    <button open-type='share' id="share1">这个第一个分享按钮</button>
    <button open-type='share' id="share2">这个第一个分享按钮</button>
/*index.js*/
Page({
    
    
  onShareAppMessage: function (res) {
    
    
    let title,imageUrl;
    console.log(res.target)if (res.from === 'button' && res.target.id == 'share1') {
    
    
      title= ‘这个是页面自定义分享按钮share1的分享事件~’;
      imageUrl='***.png';
    }
    if (res.from === 'button' && res.target.id == 'share2') {
    
    
      title= ‘这个是页面自定义分享按钮share2的分享事件~’;
      imageUrl='***.png';
    }
    if(res.from ==='menu'){
    
    
	  title= ‘这个是页面右上角的分享事件~’;
	  imageUrl='***.png';
    }
    return {
    
    
      title: title,
      imageUrl: imageUrl,//这个是分享的图片
      path: '/page/user?id=123'}
  }
})

おすすめ

転載: blog.csdn.net/shengmeshi/article/details/93612876