Documentación offline Nuxt main

utils

main Documentación oficial Licencia MITDescargado el 2026-08-02

En esta página

The main purpose of the app/utils/ directory is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.

Usage#

Method 1: Using named export

```ts twoslash [utils/index.ts] export const { format: formatNumber } = Intl.NumberFormat('en-GB', { notation: 'compact', maximumFractionDigits: 1, })

**Method 2:** Using default export

```ts twoslash [utils/random-entry.ts or utils/randomEntry.ts]
// It will be available as randomEntry() (camelCase of file name without extension)
export default function (arr: Array<any>) {
  return arr[Math.floor(Math.random() * arr.length)]
}

You can now use auto imported utility functions in .js, .ts and .vue files

```vue [app/app.vue] ```

:read-more{to="/docs/4.x/guide/concepts/auto-imports"}

:link-example{to="/docs/4.x/examples/features/auto-imports"}

::tip The way app/utils/ auto-imports work and are scanned is identical to the app/composables/ directory. ::

::important These utils are only available within the Vue part of your app. :br Only server/utils are auto-imported in the server/ directory. ::

::tip Types can be auto-imported the same way. Put app-only types in app/types/, server-only types in server/types/, and types shared between both in shared/types/. ::