Currently, @nuxt/fonts seems to load fonts only at build-time.
In my app, users can customize their theme (colors and fonts). These settings are stored in a database and applied via CSS variables.
I need a way to load a font family dynamically at runtime (e.g., via a composable or utility) while still benefiting from the module's features (local hosting, GDPR compliance, and provider abstraction).
Example:
<script setup>
const { data } = await useFetch('/api/settings')
// Something like this would be great:
useFont(fontName)
const themeStyles = computed(() => ({
'--current-font': data.value.font,
}))
</script>
<template>
<div :style="themeStyles" class="font-custom">
Hello World
</div>
</template>
<style scoped>
.font-custom {
font-family: var(--main-font);
}
</style>
Currently,
@nuxt/fontsseems to load fonts only at build-time.In my app, users can customize their theme (colors and fonts). These settings are stored in a database and applied via CSS variables.
I need a way to load a font family dynamically at runtime (e.g., via a composable or utility) while still benefiting from the module's features (local hosting, GDPR compliance, and provider abstraction).
Example: