做移动端商城项目,避免不了微信分享功能。
最近在用h5+plus做分享功能(技术地址:http://www.html5plus.org/doc/zh_cn/share.html#plus.share.ServicesSuccessCallback)
share 分享模块
html代码:
//微信分享
vxShare(num) {
var t = this; //因为用的vue框架,这里需要用到this ,如果没有用可注释
plus.share.getServices(function(e) {
t.shareData = e; //这个回调函数的参数 e 就包含了 所有对象的数组 //在这个数组里 找到属于微信的对象 循环匹配查找
for (var i in e) {
if ("weixin" == e[i].id) {
t.sharewx = e[i]; //保存到变量里 (之后即可使用该对象发起分享)
if (num == 1) {
let msg = {
type: "web", //分享的内容的类型
title: "",
content: "内容",
thumbs:[""]
href: "https://www.xxxxxx.com/",
extra: { scene: "WXSceneSession" } // 'WXSceneSession'分享给好友,'WXSceneTimeline'分享到朋友圈
}; //msg对象的属性和参数 官方文档里有说明 //这里就用到了上面获取到的 微信对象 使用send发起分享
t.sharewx.send(
msg,
function() {
console.log("分享成功");
},
function(error) {
console.log("分享失败");
}
);
} else if (num == 2) {
let msg = {
type: "web", //分享的内容的类型
title: "",
content: "内容"
thumbs: [""],//缩略图
href: "https:xxxxxxxx.com/",
extra: { scene: "WXSceneTimeline" } // 'WXSceneSession'分享给好友,'WXSceneTimeline'分享到朋友圈
}; //msg对象的属性和参数 官方文档里有说明 //这里就用到了上面获取到的 微信对象 使用send发起分享
t.sharewx.send(
msg,
function() {
console.log("分享成功");
},
function(error) {
console.log("分享失败");
}
);
}
}
}
});
},