码迷,mamicode.com
首页 > 微信 > 详细

微信小程序一个页面多个按钮分享怎么处理

时间:2018-11-18 17:02:39      阅读:554      评论:0      收藏:0      [点我收藏+]

标签:page   例子   函数   UNC   事件   pen   微信小程序   component   sage   

首先呢,第一步先看api文档:

组件:button

https://developers.weixin.qq.com/miniprogram/dev/component/button.html

框架-逻辑层-注册页面-页面事件处理函数:onShareAppMessage

https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html#%E9%A1%B5%E9%9D%A2%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0

监听用户点击页面内转发按钮(<button> 组件 open-type="share")或右上角菜单“转发”按钮的行为,并自定义转发内容。

代码区html

<view>
    <button open-type=‘share‘ id="1">1</button>
    <button open-type=‘share‘ id="2">2</button>
</view>

代码区javascript

  /**
    * 用户点击右上角分享
    */
  onShareAppMessage: function (res) {
    if (res.from === ‘button‘) {
      // 来自页面内转发按钮
      if (res.target.id == 1) {
        return {
          title: ‘自定义1111转发标题‘,
          path: ‘/page/user?id=123‘
        }
      }
      if (res.target.id == 2) {
        return {
          title: ‘自定义22222转发标题‘,
          path: ‘/page/user?id=123‘
        }
      }
    } else {
      return {
        title: ‘自定义转发标题‘,
        path: ‘/page/user?id=123‘
      }

    }

  }

以上代码主要是通过button按钮组件的id来进行区分的,在javascript中的onShareAppMessage中的res.target.id加以区分,同一个页面,去分享多个功能的例子。

 

微信小程序一个页面多个按钮分享怎么处理

标签:page   例子   函数   UNC   事件   pen   微信小程序   component   sage   

原文地址:https://www.cnblogs.com/kpengfang/p/9978363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!