vue项目history模式下微信分享相关问题
2024-10-18 03:47:00
import wx from '@/utils/wx'
import { shareApi } from '@/api' // 微信验证
export function requireConfig() {
let url = window.location.href shareApi.share({
url: url
}).then(res => {
if (res.code === 200) {
wx.config({
debug: false,
appId: res.data.appid, // 必填,企业号的唯一标识,此处填写企业号corpid
timestamp: res.data.timestamp, // 必填,生成签名的时间戳
nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
signature: res.data.signature, // 必填,签名,见附录1
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage'
]
})
}
})
} // 验证分享
export function requireShare(title, desc, link, imgUrl) {
let u = navigator.userAgent
// 安卓需要重新验证
if (u.indexOf('Android') > -1) {
requireConfig()
} wx.ready(function() {
// 分享给朋友
wx.onMenuShareAppMessage({
title: title, // 分享标题
desc: desc, // 分享描述
link: `http://share.tcm317.com${link}`, // 分享链接
imgUrl: imgUrl, // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function() {
// 用户确认分享后执行的回调函数
},
cancel: function() {
// 用户取消分享后执行的回调函数
}
})
// 分享给朋友圈
wx.onMenuShareTimeline({
title: title, // 分享标题
link: `http://share.tcm317.com${link}`, // 分享链接
imgUrl: imgUrl, // 分享图标
success: function() {
// 用户确认分享后执行的回调函数
},
cancel: function() {
// 用户取消分享后执行的回调函数
}
})
})
}
APP.vue
<template>
<div id="app">
<router-view/>
</div>
</template> <script>
import { requireConfig } from '@/utils' export default {
data() {
return { }
},
mounted() {
requireConfig()
},
methods: { }
}
</script> <style lang="scss"> </style>
需要分享的页面
requireShare(
'分享标题',
'分享简介',
'分享地址',
'分享封面'
)
最新文章
- vue 导航钩子
- hander消息机制原理
- 体验最火的敏捷——SCRUM(厦门,2014.1.4)
- 单调队列优化DP,多重背包
- c里面的fflush函数
- H5 App开发用WeX5垃圾 试用一周,我果断放弃了wex5
- C/C++ 排序&;&;查找算法(面试)
- Thinkpad X240修改bios引导方式
- BestCoder Round #76 解题报告
- android中的Handler和Runnable
- python:利用urllib查找计算机二级准考证号
- 浅述 Java 并发
- plsql部分字段中文乱码,sqlplus中文乱码
- 程序员面试宝典3TH-ch7.2
- Python爬虫之正则表达式(2)
- spring注解注入:<;context:component-scan>;详解
- 转载:gc的概念,如果A和B对象循环引用,是否可以被GC?
- py4CV例子3Mnist识别和ANN
- learning ddr DLL-off mode
- Python科学计算技巧积累四——双y轴图像绘制