商城系统 注册

微信小程序分享功能实现教程,小程序分享功能如何实现

2020-09-27|HiShop
导读:WXML 代码 view class=carDesc carDesc1 text金氏养猪场/text button class=share id=shareBtn open-type=share type=primary hover-class=other-button-hover image src=../../images/share.png/image 分享 /button /view js代码 onShareAppMessa...

应用小程序时,需要将小程序分享到朋友圈,或者微信群,那么小程序分享功能要如何实现,下面给大家介绍。

WXML 代码

 <view class='carDesc carDesc1'>
      <text>金氏养猪场</text>
      <button class='share' id="shareBtn" open-type="share" type="primary" hover-class="other-button-hover">
        <image src='../../images/share.png'></image>
        分享
      </button>
    </view>

 

微信小程序分享功能实现教程,小程序分享功能如何实现

 js代码

 

 onShareAppMessage: function (ops) {
   if (ops.from === 'button') {
     // 来自页面内转发按钮
     console.log(ops.target)
   }
   return {
     title: 'xx小程序',
     path: 'pages/index/index',
     success: function (res) {
       // 转发成功
       console.log("转发成功:" + JSON.stringify(res));
     },
     fail: function (res) {
       // 转发失败
       console.log("转发失败:" + JSON.stringify(res));
     }
   }

 }

回调结果:

回调类型 errMsg 说明
success shareAppMessage:ok 转发成功
fail shareAppMessage:fail cancel 用户取消转发
fail shareAppMessage:fail (detail message) 转发失败,其中 detail message 为详细失败信息


HiShop小程序工具提供多类型商城/门店小程序制作,可视化编辑 1秒生成5步上线。通过拖拽、拼接模块布局小程序商城页面,所看即所得,只需要美工就能做出精美商城。

更多小程序资讯,尽在:www.hishop.com.cn/xiaocx/

电话咨询 预约演示 0元开店