VueUse Nuxt Module providing seamless integration of VueUse composables with automatic import capabilities for Nuxt applications
npx @tessl/cli install tessl/npm-vueuse--nuxt@13.9.0VueUse Nuxt Module provides seamless integration of VueUse composables with automatic import capabilities for Nuxt applications. It enables developers to use Vue Composition API utilities from the VueUse library without manual imports, while intelligently avoiding conflicts with Nuxt's built-in utilities.
npm install @vueuse/nuxt @vueuse/core// The module is used in nuxt.config.ts, not imported directly in components
export default defineNuxtConfig({
modules: ['@vueuse/nuxt']
});For advanced use cases requiring direct access:
import nuxtModule from "@vueuse/nuxt";
import type { VueUseNuxtOptions } from "@vueuse/nuxt";Add to your Nuxt configuration to enable auto-imports for VueUse composables:
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@vueuse/nuxt'],
vueuse: {
// Optional configuration
autoImports: true, // Enable auto-imports (default: true)
ssrHandlers: false // Enable SSR handlers (default: false, experimental)
}
});Once configured, VueUse composables are automatically available in your components:
<template>
<div>
<p>Mouse position: {{ x }}, {{ y }}</p>
<p>Window size: {{ width }} x {{ height }}</p>
</div>
</template>
<script setup>
// No imports needed - auto-imported by the module
const { x, y } = useMouse();
const { width, height } = useWindowSize();
</script>The module consists of several key components:
The main export that configures VueUse integration in Nuxt applications.
/**
* VueUse Nuxt Module - Auto import for VueUse in Nuxt
*/
declare const _default: NuxtModule<VueUseNuxtOptions>;
export default _default;
interface VueUseNuxtOptions {
/**
* Enable/disable auto imports for VueUse composables
* @default true
*/
autoImports?: boolean;
/**
* Enable/disable SSR handlers for server-side rendering
* @experimental
* @default false
*/
ssrHandlers?: boolean;
}
// Supporting types from @nuxt/kit
interface NuxtModule<T = any> {
(options?: T, nuxt?: any): void | Promise<void>;
meta?: ModuleMeta;
}Module identification and configuration key.
interface ModuleMeta {
name: 'vueuse';
configKey: 'vueuse';
}VueUse functions that are disabled to avoid conflicts with Nuxt built-ins.
/**
* Functions disabled from auto-import to avoid conflicts with Nuxt
*/
declare const disabledFunctions: readonly [
'toRefs',
'toRef',
'toValue',
'useFetch',
'useCookie',
'useHead',
'useStorage',
'useImage'
];VueUse packages that are automatically imported when available.
/**
* VueUse packages supported for auto-import
*/
declare const packages: readonly [
'core',
'shared',
'components',
'motion',
'firebase',
'rxjs',
'sound',
'math',
'router'
];The module automatically imports VueUse composables from the following packages when they are available:
@vueuse/core - Core composables (always available)@vueuse/components - Vue component utilities@vueuse/motion - Animation and motion utilities@vueuse/firebase - Firebase integration@vueuse/rxjs - RxJS integration@vueuse/sound - Audio utilities@vueuse/math - Mathematical utilities@vueuse/router - Vue Router utilitiesOnly functions with names 4+ characters that don't conflict with disabled functions are auto-imported.
When ssrHandlers: true is enabled, the module provides server-side rendering support:
/**
* SSR handlers for VueUse composables in server context
*/
interface SSRHandlers {
/**
* Provides cookie-based storage implementation for SSR
* Uses Nuxt's useCookie for persistent storage
*/
getDefaultStorage(): {
getItem(key: string): any;
setItem(key: string, value: any): void;
removeItem(key: string): void;
};
/**
* Updates HTML attributes in SSR context
* Supports 'html' and 'body' selectors via useHead
*/
updateHTMLAttrs(selector: 'html' | 'body', attr: string, value: any): void;
}The module automatically configures:
Extends Nuxt's configuration types to include VueUse options.
declare module '@nuxt/schema' {
interface NuxtConfig {
vueuse?: VueUseNuxtOptions;
}
interface NuxtOptions {
vueuse?: VueUseNuxtOptions;
}
}The module handles several error scenarios:
A CommonJS proxy is provided for legacy module systems:
/**
* CommonJS proxy to bypass jiti transforms from Nuxt 2
*/
declare const commonjsProxy: {
default: (...args: any[]) => Promise<any>;
meta: {
name: string;
version: string;
[key: string]: any;
};
};