1.安装weixin-js-sdk
npm install weixin-js-sdk
2.创建文件并引入
- 在src下创建common目录
- 在common目录下创建wxshare.js
3.在wxshare.js中编写插件
import wx from 'weixin-js-sdk'
import URL from '@/common/urlConfig'
export const shareTitle = '测试';
export const shareUrl = '测试连接';
export const shareImg = '测试图片';
export const shareDesc = '测试详情';
export const commonShare = (_this, shareTitle, shareUrl, shareImg, shareDesc) => {
let url = window.location.href;
let data = {
url: url
};
_this.$axios.post(URL.vip.insertApplyRecord, data).then(res => {
if (res.status == 1){
let data = res.data
wx.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage"]
});
wx.ready(function () {
wx.onMenuShareTimeline({
title: shareTitle,
link: shareUrl,
imgUrl: shareImg,
success: function () {
},
cancel: function () {
}
});
wx.onMenuShareAppMessage({
title: shareTitle,
desc: shareDesc,
link: shareUrl,
imgUrl: shareImg,
type: "",
dataUrl: "",
success: function () {
},
cancel: function () {
}
});
});
}
})
};
4.在需要分享页面编写
import {commonShare, shareTitle, shareUrl, shareImg, shareDesc} from "@/common/wxshare";
commonShare(this, shareTitle, shareUrl, shareImg, shareDesc);