utils

utils/ ディレクトリを使用して、アプリケーション全体でユーティリティ関数を自動インポートできます。

app/utils/ ディレクトリの主な目的は、Vue のコンポーザブルと他の自動インポートされるユーティリティ関数の意味的な区別を可能にすることです。

使用方法

方法 1: 名前付きエクスポートを使用する

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

方法 2: デフォルトエクスポートを使用する

utils/random-entry.ts または 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)]
}

.js.ts、および .vue ファイルで、自動インポートされたユーティリティ関数を使用できるようになりました。

app/app.vue
<template>
  <p>{{ formatNumber(1234) }}</p>
</template>
Docs > 4 X > Guide > Concepts > Auto Imports で詳細をご覧ください。
Docs > 4 X > Examples > Features > Auto Imports でライブサンプルを読み、編集する。
app/utils/ の自動インポートの仕組みとスキャン方法は、app/composables/ ディレクトリと同一です。
これらのユーティリティは、アプリの Vue 部分でのみ利用可能です。
server/ ディレクトリでは、server/utils のみが自動インポートされます。