做移動端商城項目,避免不了微信分享功能。
最近在用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("分享失敗");
}
);
}
}
}
});
},