代码实现
- 引入weixin-js-sdk
import { getWeixinInfo } from '@/api'
export function share () {
const _url = window.location.href.split('#')[0]
const { res } = getWeixinInfo({ url: _url })
if (data.res) {
wxConfig(res.data)
}
}
export function wxConfig (data) {
wx.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: [
'onMenuShareAppMessage',
'onMenuShareTimeline',
]
});
wx.ready(function () {
wx.onMenuShareAppMessage({
title: '分享标题',
desc: '分享描述',
link: process.env.VUE_APP_AUTH,
imgUrl: 'https://hlwyy-test.obs-cn-shanghai.pinganyun.com/1.jpg',
success: function () {
}
});
wx.onMenuShareTimeline({
title: '分享标题',
link: process.env.VUE_APP_AUTH,
imgUrl: 'https://hlwyy-test.obs-cn-shanghai.pinganyun.com/1.jpg',
success: function () {
}
});
});
}
实现效果
