fix: global reactive attrs

change to ref for primitive types, use provide/inject instead of globalConfig
This commit is contained in:
Tony Yang
2025-04-17 12:32:01 +08:00
parent d90d2c5e3c
commit ab0e5f5e36
4 changed files with 13 additions and 9 deletions
+2
View File
@@ -5,6 +5,8 @@ import VueHcaptcha from '@hcaptcha/vue3-hcaptcha';
import { RecaptchaV2, useRecaptcha } from "vue3-recaptcha-v2"; import { RecaptchaV2, useRecaptcha } from "vue3-recaptcha-v2";
import VueTurnstile from 'vue-turnstile'; import VueTurnstile from 'vue-turnstile';
const $darkMode = inject('$darkMode');
const { handleReset: handleRecaptchaReset } = useRecaptcha(); const { handleReset: handleRecaptchaReset } = useRecaptcha();
const props = defineProps({ const props = defineProps({
+3 -1
View File
@@ -1,8 +1,10 @@
<script setup> <script setup>
import { useRouter, RouterLink } from 'vue-router'; import { useRouter, RouterLink } from 'vue-router';
import { computed } from 'vue'; import { computed, inject } from 'vue';
import { useAuthStore } from '../stores/auth'; import { useAuthStore } from '../stores/auth';
const $isMobile = inject('$isMobile');
const router = useRouter(); const router = useRouter();
const authStore = useAuthStore(); const authStore = useAuthStore();
+4 -4
View File
@@ -1,14 +1,14 @@
import { reactive } from 'vue'; import { ref } from 'vue';
const darkModeMediaQuery = '(prefers-color-scheme: dark)'; const darkModeMediaQuery = '(prefers-color-scheme: dark)';
const matchMedia = window.matchMedia(darkModeMediaQuery); const matchMedia = window.matchMedia(darkModeMediaQuery);
const darkMode = reactive(matchMedia.matches); const darkMode = ref(matchMedia.matches);
matchMedia.addEventListener('change', (event) => { matchMedia.addEventListener('change', (event) => {
darkMode = event.matches; darkMode.value = event.matches;
}); });
export const install = (app) => { export const install = (app) => {
app.config.globalProperties.$darkMode = darkMode; app.provide('$darkMode', darkMode);
} }
+4 -4
View File
@@ -1,14 +1,14 @@
import { reactive } from 'vue'; import { ref } from 'vue';
const mobileMediaQuery = 'screen and (max-width: 768px)'; const mobileMediaQuery = 'screen and (max-width: 768px)';
const matchMedia = window.matchMedia(mobileMediaQuery); const matchMedia = window.matchMedia(mobileMediaQuery);
const isMobile = reactive(matchMedia.matches); const isMobile = ref(matchMedia.matches);
matchMedia.addEventListener('change', (event) => { matchMedia.addEventListener('change', (event) => {
isMobile = event.matches; isMobile.value = event.matches;
}); });
export const install = (app) => { export const install = (app) => {
app.config.globalProperties.$isMobile = isMobile; app.provide('$isMobile', isMobile);
} }