• 微信小程序之API 转发给好友 (Page.onShareAppMessage)


    wxml部分

    转发事件一定是绑在 button 组件上面.给button组件设置属性:open-type="share"
    点击按钮直接就会触发转发的方法,可以转发给指定的微信好友.
    但是这个需求还不够,用户那边收到的是 转发的那个页面,点进去以后也是那个页面

     <button class='weixin' open-type="share">
         <view class='wechatImg'>
             <image class='wechatIcon' src='../../images/wechat.png'></image>
         </view>
         <view class='sentFriend'>发送给好友</view>
    </button>
    
    js部分
    /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function(res) {
        let that = this;
        // console.log('主图------------->',that.data.goodsObj.MainImages)
        return {
          title: "发送给好友",
          imageUrl: that.data.goodsObj.MainImages,
          success: function(res) {
            console.log(res, "转发成功")
          },
          fail: function(res) {
            console.log(res, "转发失败")
          }
        }
    
      },
    

    如果只保留页面按钮的转发,关闭微信右上角的转发 则可:
    1.在onload关闭

     onLoad: function(options) {
    
        // 隐藏右上角分享
        wx.hideShareMenu()
    }
    
    /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function(res) {
        if (res.from === "button") {
          console.log(res)
          let that = this;
          let v = that.data.OrderNumber;
          that.setData({
            flag: false,
            v: v
          })
          console.log(v, 'v===========')
          return {
            title: that.data.BrandName,
            path: 'pages/index/index?t=' + 50 + '&v=' + v,
            success: function(res) {
              console.log(res, "转发成功")
    
            },
            fail: function(res) {
              console.log(res, "转发失败")
            }
          }
        } else {
          console.log(res)
        }
      },
    
  • 相关阅读:
    浅析C#中的Thread ThreadPool Task和async/await
    C#中的集合类型
    WPF: StaticResource vs DynamicResource
    .NET程序员需要了解的概念、名词、术语--持续更新
    VisualStudio常见问题
    一些有用的.NET开源库--持续更新
    在MSBuild中使用Task实现自动引用指定版本的NuGet包
    C#与JMS的连接问题
    EventLog学习记录
    windows app设计原则总结-持续更新...
  • 原文地址:https://www.cnblogs.com/jessie-xian/p/11571635.html
Copyright © 2020-2023  润新知