The main purpose of the app/utils/ directory is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.
方法 1: 使用命名导出
export const { format: formatNumber } = Intl.NumberFormat('en-GB', {
notation: 'compact',
maximumFractionDigits: 1,
})
方法 2: 使用默认导出
// 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 文件中使用自动导入的工具函数
<template>
<p>{{ formatNumber(1234) }}</p>
</template>
app/utils/ 的自动导入工作方式和扫描方式与 app/composables/ 目录完全相同。