app/utils/ 디렉터리의 주요 목적은 Vue 컴포저블과 기타 자동 임포트되는 유틸리티 함수들 사이를 의미적으로 구분할 수 있게 하는 것입니다.
방법 1: 이름이 있는 export 사용
export const { format: formatNumber } = Intl.NumberFormat('en-GB', {
notation: 'compact',
maximumFractionDigits: 1,
})
방법 2: 기본 export 사용
// 확장자를 제외한 파일 이름을 camelCase로 변환한 randomEntry() 로 사용할 수 있습니다
export default function (arr: Array<any>) {
return arr[Math.floor(Math.random() * arr.length)]
}
이제 .js, .ts, .vue 파일에서 자동 임포트된 유틸리티 함수를 사용할 수 있습니다.
<template>
<p>{{ formatNumber(1234) }}</p>
</template>
app/utils/의 자동 임포트 방식과 스캔 방식은 app/composables/ 디렉터리와 동일합니다.