zoukankan      html  css  js  c++  java
  • 微信小程序一个页面多个按钮分享怎么处理

    首先呢,第一步先看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加以区分,同一个页面,去分享多个功能的例子。

  • 相关阅读:
    JS 打印实现部分打印
    window.opener和window.open
    js中!和!!的区别及用法
    SQL循环表里的数据
    简明lua教程[转]
    mysql调优技巧-profiles
    MySQL的InnoDB的幻读问题
    linux exec命令
    常用正则搜集整理
    flashget for linux安装问题解决
  • 原文地址:https://www.cnblogs.com/kpengfang/p/9978363.html
Copyright © 2011-2022 走看看