share.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import config from '@/core/config/index.js'
  2. export default {
  3. data() {
  4. return {
  5. share: {
  6. // 转发的标题 (默认标题)
  7. title: config.get('name'),
  8. // 默认是当前页面,必须是以‘/’开头的完整路径
  9. path: `/pages/home/index`,
  10. //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,
  11. //支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  12. imageUrl: config.getResource('logo.png')
  13. }
  14. }
  15. },
  16. // 发送给朋友
  17. onShareAppMessage(res) {
  18. let shareInfo = uni.getStorageSync('shareInfo')
  19. return {
  20. title: shareInfo.title || this.share.title,
  21. imageUrl: shareInfo.imgUrl || this.share.imageUrl,
  22. path: shareInfo.path || this.share.path
  23. }
  24. },
  25. //分享到朋友圈
  26. onShareTimeline(res) {
  27. let shareInfo = uni.getStorageSync('shareInfo')
  28. return {
  29. title: shareInfo.title || this.share.title,
  30. imageUrl: shareInfo.imgUrl || this.share.imageUrl,
  31. path: shareInfo.path || this.share.path
  32. }
  33. }
  34. }