useWxshared.js 893 B

12345678910111213141516171819202122232425262728293031323334
  1. import wxshare from "@/utils/wxshare";
  2. import { onMounted } from "vue";
  3. const initWxShare = async () => {
  4. // onMounted(async () => {
  5. try {
  6. // await new Promise((r) => setTimeout(r, 1000));
  7. const title = document.title;
  8. const link = window.location.href;
  9. // const desc = '测试微信分享'
  10. const imgUrl = document.querySelector('meta[name="cover"]').content || "";
  11. const desc =
  12. document.querySelector('meta[name="description"]').content || "";
  13. // const imgUrl = document.document.querySelector('meta[name="description"]').content
  14. // title, link, imgUrl, desc
  15. console.log("当前分享imgUrl", imgUrl);
  16. await wxshare({
  17. title,
  18. link,
  19. desc,
  20. imgUrl,
  21. });
  22. } catch (error) {
  23. console.error(error);
  24. }
  25. // })
  26. };
  27. export function useWxShared() {
  28. return {
  29. initWxShare,
  30. };
  31. }