Share.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div v-if="url" class="share">
  3. <nuxt-link
  4. v-for="network in networks"
  5. :key="network.name"
  6. :href="network.url"
  7. target="_blank"
  8. :style="{ color: network.colorOnHover }"
  9. >
  10. <v-icon :icon="network.icon" />
  11. </nuxt-link>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import type { Ref } from "vue";
  16. import type { SocialNetworkShareBtn } from "~/types/interface";
  17. const url: Ref<string | null> = ref(null);
  18. const networks: Ref<Array<SocialNetworkShareBtn>> = ref([]);
  19. if (process.client) {
  20. url.value = window.location.href;
  21. networks.value = [
  22. {
  23. name: "Facebook",
  24. icon: "fa-brands fa-facebook",
  25. colorOnHover: "#135fc2",
  26. url: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url.value)}`,
  27. },
  28. {
  29. name: "Twitter",
  30. icon: "fa-brands fa-twitter",
  31. colorOnHover: "#1781c2",
  32. url: `https://twitter.com/intent/tweet?url=${encodeURIComponent(url.value)}`,
  33. },
  34. {
  35. name: "Messenger",
  36. icon: "fa-brands fa-facebook-messenger",
  37. colorOnHover: "#0085ff",
  38. url: `https://messenger.com`,
  39. },
  40. {
  41. name: "Instagram",
  42. icon: "fa-brands fa-instagram",
  43. colorOnHover: "#d0006a",
  44. url: "https://instagram.com",
  45. },
  46. {
  47. name: "Linkedin",
  48. icon: "fa-brands fa-linkedin",
  49. colorOnHover: "#006291",
  50. url: `https://www.linkedin.com/shareArticle?mini=true&url=${encodeURIComponent(url.value)}`,
  51. },
  52. {
  53. name: "Email",
  54. icon: "fas fa-envelope",
  55. colorOnHover: "#292929",
  56. url: `mailto:?body=${url.value}`,
  57. },
  58. ];
  59. }
  60. </script>
  61. <style scoped lang="scss">
  62. .share {
  63. display: flex;
  64. gap: 10px;
  65. font-size: 16px;
  66. font-weight: 400;
  67. line-height: 28px;
  68. i {
  69. font-size: 32px;
  70. margin: 0.5rem 0.3rem;
  71. color: var(--primary-color);
  72. }
  73. a:hover i {
  74. color: inherit;
  75. }
  76. }
  77. </style>