uniapp分享

首先在hbuilder底部终端,输入npm install jweixin-module --save
在export default 上面添加一行var jweixin = require('jweixin-module');
然后
onLoad() {
this.onShare();
}
onShare: function() {
const that = this;
uni.request({
url: 'https://*****/api/v1/wechatShareConfig',//这里是根据url获取config的值
method: 'get',
data: {
url: window.location.href
},
success: res => {
jweixin.config(res.data);
jweixin.error(err => {
console.log('config fail:', err);
});

                    jweixin.ready(res => {
                        var shareData = {
                            title: that.indexData.share_title,
                            desc: that.indexData.share_desc,
                            link: "https://****/index.html?entrance=share&basicid=" +basicid,
                            imgUrl: that.indexData.cover,
                            success: function(res) {
                                //用户点击分享后的回调,这里可以进行统计,例如分享送金币之类的  
                                console.log("share ready");
                            },
                            cancel: function(res) {}
                        };
                        //分享给朋友接口  
                        jweixin.updateAppMessageShareData(shareData);
                        //分享到朋友圈接口  
                        jweixin.updateTimelineShareData(shareData);
                    });
                }
            });
        },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,735评论 0 3
  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,062评论 0 2
  • 33、JS中的本地存储 把一些信息存储在当前浏览器指定域下的某一个地方(存储到物理硬盘中)1、不能跨浏览器传输:在...
    萌妹撒阅读 2,140评论 0 2
  • 概要 64学时 3.5学分 章节安排 电子商务网站概况 HTML5+CSS3 JavaScript Node 电子...
    阿啊阿吖丁阅读 9,395评论 0 3
  • 北京2018年4月1日上午,NBA常规赛勇士客战国王的比赛中,发生了令人痛心不已的一幕。比赛进行到第三节还有41...
    Curry_宇阅读 1,269评论 1 1