Skip to content

Commit a2530f2

Browse files
[autofix.ci] apply automated fixes
1 parent 5e96387 commit a2530f2

File tree

1 file changed

+27
-18
lines changed
  • content/2.concepts/4.auto-imports

1 file changed

+27
-18
lines changed

content/2.concepts/4.auto-imports/index.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ You are also able to auto-import functions exported deom custom folders or third
1414
## Built-in Auto-imports
1515

1616
Nuxt auto-imports functions and compostables to:
17-
* perform [data fetching](https://nuxt.com/docs/getting-started/data-fetching)
18-
* get access to the [app context](https://nuxt.com/docs/api/composables/use-nuxt-app) and [running config](https://nuxt.com/docs/guide/going-further/runtime-config)
19-
* manage [state](https://nuxt.com/docs/getting-started/state-management)
20-
* or define components and plugins
17+
18+
- perform [data fetching](https://nuxt.com/docs/getting-started/data-fetching)
19+
- get access to the [app context](https://nuxt.com/docs/api/composables/use-nuxt-app) and [running config](https://nuxt.com/docs/guide/going-further/runtime-config)
20+
- manage [state](https://nuxt.com/docs/getting-started/state-management)
21+
- or define components and plugins
2122

2223
```vue
2324
<script setup lang="ts">
2425
/* useFetch() is auto-imported */
2526
const { data, refresh, status } = await useFetch('/api/hello')
2627
</script>
2728
```
29+
2830
Vue 3 exposes Reactivity APIs like `ref` or `computed`, as well as lifecycle hooks and helpers that are auto-imported by Nuxt.
2931

3032
## Vue and Nuxt composables
@@ -34,18 +36,23 @@ When you are using the built-in Composition API composables provided by Vue and
3436
The global variable tracking mechanism in Vue and Nuxt imposes strict usage constraints on composables and context-specific functions. These restrictions mean that developers can typically only access these instances within specific, controlled environments:
3537

3638
1. Permitted Contexts:
37-
* Nuxt plugins
38-
* Nuxt route middleware
39-
* Vue setup functions
39+
40+
- Nuxt plugins
41+
- Nuxt route middleware
42+
- Vue setup functions
43+
4044
2. Synchronous Execution Requirement:
41-
* Composables must be called synchronously
42-
* Using await before calling a composable is generally prohibited
45+
46+
- Composables must be called synchronously
47+
- Using await before calling a composable is generally prohibited
48+
4349
3. Exceptions to the Rule:
44-
Some specialized contexts allow for asynchronous usage while maintaining the synchronous context:
45-
* `<script setup>` blocks
46-
* Components defined with `defineNuxtComponent`
47-
* Functions created with `defineNuxtPlugin`
48-
* Route middleware defined with `defineNuxtRouteMiddleware`
50+
Some specialized contexts allow for asynchronous usage while maintaining the synchronous context:
51+
52+
- `<script setup>` blocks
53+
- Components defined with `defineNuxtComponent`
54+
- Functions created with `defineNuxtPlugin`
55+
- Route middleware defined with `defineNuxtRouteMiddleware`
4956

5057
These limitations are designed to prevent state management issues and ensure clean, predictable component and application behavior during server-side rendering.
5158

@@ -54,17 +61,18 @@ If you get an error message like `Nuxt instance is unavailable` then it probably
5461
## Directory-based Auto-imports
5562

5663
Nuxt directly auto-imports files created in defined directories:
57-
* `components/` for [Vue components](https://nuxt.com/docs/guide/directory-structure/components).
58-
* `composables/` for [Vue composables](https://nuxt.com/docs/guide/directory-structure/composables).
59-
* `utils/` for helper functions and other utilities.
64+
65+
- `components/` for [Vue components](https://nuxt.com/docs/guide/directory-structure/components).
66+
- `composables/` for [Vue composables](https://nuxt.com/docs/guide/directory-structure/composables).
67+
- `utils/` for helper functions and other utilities.
6068

6169
### Explicit imports
6270

6371
Nuxt exposes every auto-import with the `#imports` alias that can be used to make the import explicit if needed.
6472

6573
```vue
6674
<script setup lang="ts">
67-
import { ref, computed } from '#imports'
75+
import { computed, ref } from '#imports'
6876
6977
const count = ref(1)
7078
const double = computed(() => count.value * 2)
@@ -88,6 +96,7 @@ This will disable auto-imports completely but it's still possible to use explici
8896
### Partially Disabling Auto-imports
8997

9098
If you want framework-specific functions like `ref` to remain auto-imported but wish to disable auto-imports for your own code (e.g., custom composables), you can set the `imports.scan` option to `false` in your `nuxt.config.ts` file:
99+
91100
```ts filename="nuxt.config.ts"
92101
export default defineNuxtConfig({
93102
imports: {

0 commit comments

Comments
 (0)