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);
                    });
                }
            });
        },

你可能感兴趣的:(uniapp分享)