onShareAppMessage

解释:页面的事件处理函数,用户点击右上角转发。

详情参见页面相关事件处理函数

示例

在开发者工具中打开

在开发者工具中打开

在 WEB IDE 中打开

代码示例

  • SWAN
  • JS
  1. <view class="wrap">
  2. <view class="card-area">
  3. <view class="tip-week">发送内容(以下字段可自由适配)</view>
  4. <view class="list-area">
  5. <view class="list-item-key-4">标题</view>
  6. <input class="list-item-value" bindinput="dataInput" data-type="title" value="{{shareData.title}}" type="text" placeholder="请输入key" />
  7. </view>
  8. <view class="list-area">
  9. <view class="list-item-key-4">内容</view>
  10. <input class="list-item-value" bindinput="dataInput" data-type="content" value="{{shareData.content}}" type="text" placeholder="请输入key" />
  11. </view>
  12. <view class="list-area">
  13. <view class="list-item-key-4">跳转页面</view>
  14. <input class="list-item-value" bindinput="dataInput" data-type="path" value="{{shareData.path}}" type="text" placeholder="请输入key" />
  15. </view>
  16. <button type="primary" open-type="share" hover-stop-propagation="true">点击打开分享面板</button>
  17. <view class="tip-week">点击右上角菜单或者点击button转发给好友</view>
  18. </view>
  19. </view>
  1. Page({
  2. data: {
  3. shareData: {
  4. title: '小程序标题',
  5. content: '世界很复杂,百度更懂你',
  6. path: 'api/onShareAppMessage/onShareAppMessage',
  7. imageUrl: 'https://b.bdstatic.com/miniapp/images/bgt_icon.png'
  8. }
  9. },
  10. onShareAppMessage() {
  11. this.data.shareData.path += '?fr=shareApp';
  12. return this.data.shareData;
  13. },
  14. dataInput(e) {
  15. let type = e.currentTarget.dataset.type;
  16. let dataInput = e.detail.value;
  17. switch (type) {
  18. case 'title':
  19. let title = 'shareData.title';
  20. this.setData({
  21. [title]: dataInput
  22. });
  23. break;
  24. case 'content':
  25. let content = 'shareData.content';
  26. this.setData({
  27. [content]: dataInput
  28. });
  29. break;
  30. case 'path':
  31. let path = 'shareData.path';
  32. this.setData({
  33. [path]: dataInput
  34. });
  35. break;
  36. }
  37. }
  38. });