在 manifest.json 的 App SDK 配置裡,勾選微信消息及朋友圈,并填寫 appid,在iOS平台使用還需要配置通用連結。
參考文檔
微信 appid 申請步驟:https://ask.dcloud.net.cn/article/208。
iOS平台微信SDK配置通用連結:https://ask.dcloud.net.cn/article/36445。
分享到微信聊天界面代碼:
html代碼:
<button @click="appToShare">分享名片</button>
JS代碼:
appToShare: function() {
uni.share({
provider: 'weixin',//分享服務提供商(即weixin|qq|sinaweibo)
scene: "WXSceneSession",//WXSceneSession(分享到聊天界面)、WXSenceTimeline(分享到朋友圈)、WXSceneFavorite(分享到微信收藏)
type: 1,
title: '分享标題',
summary: "分享描述",
href: 'www.baidu.com',//分享跳轉位址
imageUrl: '',//分享圖檔路徑(必須是線上可通路圖檔:http://xxx、https://xxx等)
success: function(res) {
console.log("success:" + JSON.stringify(res));
},
fail: function(err) {
console.log("fail:" + JSON.stringify(err));
}
});
}