Skip to content
快速导航

Nuxt3 app.config.ts - APP 配置

Nuxt3 app.config.ts应用程序配置文件提供运行时应用程序配置。它的扩展名可以是.ts.js.mjs

// app.config.ts
export default defineAppConfig({
  foo: 'bar'
})

WARNING

不要把任何私密数据放在app.config文件中。它将暴露给客户端。

定义 App Config

app.config文件中定义配置:

// app.config.ts
export default defineAppConfig({
  theme: {
    primaryColor: '#ababab'
  }
})

使用useAppConfig组合函数获取配置信息:

const appConfig = useAppConfig()

console.log(appConfig.theme)

类型接口

Nuxt 会尝试从app.config中自动生成一个类型接口。

也可以手动输入app config:

// index.d.ts
declare module '@nuxt/schema' {
  interface AppConfig {
    /** Theme configuration */
    theme: {
      /** Primary app color */
      primaryColor: string
    }
  }
}

// It is always important to ensure you import/export something when augmenting a type
export {}