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(
'分享标题',
'分享简介',
'分享地址',
'分享封面'
)

最新文章

  1. vue 导航钩子
  2. hander消息机制原理
  3. 体验最火的敏捷——SCRUM(厦门,2014.1.4)
  4. 单调队列优化DP,多重背包
  5. c里面的fflush函数
  6. H5 App开发用WeX5垃圾 试用一周,我果断放弃了wex5
  7. C/C++ 排序&amp;&amp;查找算法(面试)
  8. Thinkpad X240修改bios引导方式
  9. BestCoder Round #76 解题报告
  10. android中的Handler和Runnable
  11. python:利用urllib查找计算机二级准考证号
  12. 浅述 Java 并发
  13. plsql部分字段中文乱码,sqlplus中文乱码
  14. 程序员面试宝典3TH-ch7.2
  15. Python爬虫之正则表达式(2)
  16. spring注解注入:&lt;context:component-scan&gt;详解
  17. 转载:gc的概念,如果A和B对象循环引用,是否可以被GC?
  18. py4CV例子3Mnist识别和ANN
  19. learning ddr DLL-off mode
  20. Python科学计算技巧积累四——双y轴图像绘制

热门文章

  1. sql server 查询存储过程返回值
  2. LoadRunner对sockets报文进行压力测试(脚本设计)
  3. CDH的ntp时间同步
  4. BZOJ 1053 反素数 题解
  5. P1142轰炸
  6. HDU-4332-Constructing Chimney
  7. 打印输出opencv的版本信息
  8. P4962 朋也与光玉题解
  9. Jquery复习(三)之链式调用
  10. Delphi 数据类型