2022-04-06 05:56:08 +00:00
# Auto Imports
2022-02-18 18:20:55 +00:00
2022-03-16 11:16:05 +00:00
Nuxt auto-imports helper functions, composables and Vue APIs to use across your application without explicitly importing them. Based on the directory structure, every Nuxt application can also use auto-imports for its own components, composables and plugins. Components, composables or plugins can use these functions.
2022-02-18 18:20:55 +00:00
Contrary to a classic global declaration, Nuxt preserves typings and IDEs completions and hints, and only includes what is actually used in your production code.
2022-03-16 11:16:05 +00:00
::alert{type=info icon=💡}
In the documentation, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code.
2022-04-16 13:53:36 +00:00
You can find a reference for auto-imported [composables ](/api/composables/use-async-data ) and [utilities ](/api/utils/$fetch ) in the API section.
2022-02-18 18:20:55 +00:00
::
2022-03-14 16:01:20 +00:00
::alert{type=warning}
2022-04-06 05:56:08 +00:00
Auto imports don't currently work within the [server directory ](/guide/directory-structure/server ).
2022-03-14 16:01:20 +00:00
::
2022-08-13 07:27:04 +00:00
## Nuxt Auto-imports
2022-02-18 18:20:55 +00:00
2022-09-13 12:54:31 +00:00
Nuxt auto-imports functions and composables to perform [data fetching ](/getting-started/data-fetching ), get access to the [app context ](/api/composables/use-nuxt-app ) and [runtime config ](/guide/going-further/runtime-config ), manage [state ](/getting-started/state-management ) or define components and plugins.
2022-02-18 18:20:55 +00:00
```vue
< script setup >
/* useAsyncData() and $fetch() are auto-imported */
const { data, refresh, pending } = await useAsyncData('/api/hello', () => $fetch('/api/hello'))
< / script >
```
2022-08-13 07:27:04 +00:00
## Vue Auto-imports
2022-02-18 18:20:55 +00:00
Vue 3 exposes Reactivity APIs like `ref` or `computed` , as well as lifecycle hooks and helpers that are auto-imported by Nuxt.
```vue
< script setup >
/* ref() and computed() are auto-imported */
const count = ref(1)
const double = computed(() => count.value * 2)
< / script >
```
2022-08-13 07:27:04 +00:00
## Directory-based Auto-imports
2022-02-18 18:20:55 +00:00
Nuxt directly auto-imports files created in defined directories:
2022-04-06 05:56:08 +00:00
- `components/` for [Vue components ](/guide/directory-structure/components ).
- `composables/` for [Vue composables ](/guide/directory-structure/composables ).
2022-02-18 18:20:55 +00:00
2022-08-13 07:27:04 +00:00
## Explicit Imports
2022-02-18 18:20:55 +00:00
2022-04-08 13:09:00 +00:00
Nuxt exposes every auto-import with the `#imports` alias that can be used to make the import explicit if needed:
2022-02-18 18:20:55 +00:00
```vue
< script setup >
import { ref, computed } from '#imports'
const count = ref(1)
const double = computed(() => count.value * 2)
< / script >
```
2022-08-24 08:44:38 +00:00
## Disable Auto-imports
In case you want to disable auto-imports, you can set `imports.autoImport` to `false` .
```ts [nuxt.config.ts]
export default defineNuxtConfig({
imports: {
autoImport: false
}
})
```
This will disable implicit auto imports completely but it's still possible to use [Explicit Imports ](#explicit-imports ).