CookieBanner.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <div v-if="isVisible" class="fixed bottom-0 left-0 right-0 z-50 p-4 animate-in slide-in-from-bottom-4 duration-500">
  3. <div class="max-w-4xl mx-auto bg-foreground text-background p-4 sm:p-6 rounded-2xl shadow-2xl flex flex-col sm:flex-row items-center gap-4 sm:gap-6">
  4. <div class="flex-1 text-sm font-medium text-background/90 text-center sm:text-left">
  5. {{ t("cookies.message") }}
  6. </div>
  7. <div class="flex flex-shrink-0 gap-3 w-full sm:w-auto">
  8. <button @click="leave" class="flex-1 sm:flex-none px-4 py-2 bg-background/20 hover:bg-background/30 text-background rounded-full font-bold text-sm transition-colors whitespace-nowrap">
  9. {{ t("cookies.leave") }}
  10. </button>
  11. <button @click="accept" class="flex-1 sm:flex-none px-6 py-2 bg-primary text-primary-foreground rounded-full font-bold text-sm transition-colors whitespace-nowrap">
  12. {{ t("cookies.accept") }}
  13. </button>
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script setup lang="ts">
  19. import { ref, onMounted } from 'vue';
  20. import { useI18n } from 'vue-i18n';
  21. const { t } = useI18n();
  22. const isVisible = ref(false);
  23. onMounted(() => {
  24. const consent = localStorage.getItem('cookie_consent');
  25. if (!consent) {
  26. isVisible.value = true;
  27. }
  28. });
  29. const accept = () => {
  30. localStorage.setItem('cookie_consent', 'accepted');
  31. isVisible.value = false;
  32. };
  33. const leave = () => {
  34. window.location.href = "https://www.google.com";
  35. };
  36. </script>