utils

애플리케이션 전역에서 유틸리티 함수를 자동 임포트하기 위해 utils/ 디렉터리를 사용하세요.

app/utils/ 디렉터리의 주요 목적은 Vue 컴포저블과 기타 자동 임포트되는 유틸리티 함수들 사이를 의미적으로 구분할 수 있게 하는 것입니다.

사용법

방법 1: 이름이 있는 export 사용

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

방법 2: 기본 export 사용

utils/random-entry.ts or utils/randomEntry.ts
// 확장자를 제외한 파일 이름을 camelCase로 변환한 randomEntry() 로 사용할 수 있습니다
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>
Read more in Docs > 4 X > Guide > Concepts > Auto Imports.
Read and edit a live example in Docs > 4 X > Examples > Features > Auto Imports.
app/utils/의 자동 임포트 방식과 스캔 방식은 app/composables/ 디렉터리와 동일합니다.
이 유틸 함수들은 앱의 Vue 영역에서만 사용할 수 있습니다.
server/ 디렉터리에서는 server/utils만 자동 임포트됩니다.