```
npm?安裝?jwei Xin-模塊?-保存
```
2.創建文件share.wx.js
```
//介紹微信jssdk。
const jweixin = require(' jweixin-module ')
const install = (Vue,VM)= & gt;{
// shareInfo: {
//標題:'標題',
// desc:'描述',
// link: location.origin,
//imgUrl:'/uploads/we chat _ img/2020/07/29/20200729095315-5f 20d 68 b 1 ea0d . jpg '
// }
const init =(shareInfo = { })= & gt;{
//獲取微信jssdk進行分享。
vm。$u.api.getWxjssdk({
url: location.href
}).然後(res = & gt{
res = res.data
vm。$u.vuex('vuex_wxjssdk ',res)
console.log(res)
jweixin.config({
Debug: res.debug,//打開調試模式,所有被調用API的返回值都會在客戶端告警中出來。如果想查看進來的參數,可以在pc端打開,參數信息會通過日誌打出來,日誌只會在pc端打印出來。
AppId: res.appId,//必選,微信官方賬號的唯壹標識。
Timestamp: res.timestamp,//必選,生成簽名的時間戳。
non castr:RES . non castr,//必需,用於生成簽名的隨機字符串。
Signature: res.Signature,//必選,signature。
JsApiList: res.jsApiList //必選,要使用的JS接口列表。
});
jweixin . ready(()= & gt;{
console.log(shareInfo.title)
//與朋友分享
jweixin . updateappmessagesharedata({
標題:shareInfo.title,
desc: shareInfo.desc
鏈接:shareInfo.link,
imgUrl: shareInfo.imgUrl,
成功:()= & gt{
//設置成功
}
})
//分享到朋友圈
jweixin . updatetimelinesharedata({
標題:shareInfo.title,
鏈接:shareInfo.link,
imgUrl: shareInfo.imgUrl,
成功:()= & gt{
//設置成功
}
})
//分享到朋友圈
jweixin.onMenuShareTimeline({
標題:shareInfo.title,
鏈接:shareInfo.link,
imgUrl: shareInfo.imgUrl,
成功:()= & gt{
}
})
//與朋友分享
jweixin . onmenushareappmessage({
標題:shareInfo.title,
desc: shareInfo.desc
鏈接:shareInfo.link,
imgUrl: shareInfo.imgUrl,
成功:()= & gt{
}
})
});
jweixin.error(function(res) {
//當配置信息驗證失敗時,將執行error函數。如果由於簽名過期而導致驗證失敗,可以在config的調試模式或返回的res參數中查看具體的錯誤信息。對於SPA,可以在此處更新簽名。
console.log(res)
});
})
};
//將所有定義的接口名放入對象中,掛載到vm下。$u.api(因為vm就是這個,也就是這個。$u.api)。
vm。$u.share = {
初始化
};
}
導出默認值{
安裝
}
```
3.將以下內容添加到main.js應用程序中。$mount()
```
//微信jssdk初始化
從“@/common/share.wx.js”導入wxshare
Vue.use(wxshare,app)
```
4.打電話
```
這個。$u.share.init({
標題:'標題',
Desc:“描述”,
鏈接:location.origin,
ImgUrl:“共享圖片地址”
})
```