配置全解
nuxt.config.ts 中 dict 配置项的完整参考,含每个字段的类型、默认值和说明。
本章列出 nuxt.config.ts 中 dict 配置的所有字段。
enable
| 类型 | 默认值 | 说明 |
|---|---|---|
boolean | true | 是否启用字典模块 |
logLevel
| 类型 | 默认值 | 说明 |
|---|---|---|
number | 3 | 日志级别:0=静默, 1=错误, 2=警告, 3=信息, 4=调试, 5=详细 |
api.baseURL
| 类型 | 默认值 | 说明 |
|---|---|---|
string | '/api' | API 基础地址。支持绝对 URL 或相对路径 |
api.dictEndpoint
| 类型 | 默认值 | 说明 |
|---|---|---|
string | '/dict/list' | 字典列表接口路径 |
api.versionEndpoint
| 类型 | 默认值 | 说明 |
|---|---|---|
string | '/dict/version' | 版本号接口路径 |
api.adapter
| 类型 | 默认值 | 说明 |
|---|---|---|
string | undefined | undefined | 自定义适配器的文件路径(如 '~/dict/dict-adapter.ts')。若文件存在于约定路径 ~/dict/dict-adapter.ts,模块会自动发现并注册,无需手动配置。命名仓库使用 stores.xxx.adapter,详见 自定义适配器 |
api.lazy
| 类型 | 默认值 | 说明 |
|---|---|---|
boolean | false | 是否惰性检查版本号。false 时页面加载立即检查,true 时延迟到首次 getDict() 调用时检查 |
仓库少时建议 false(立即检查),仓库多且不一定全用到时设为 true 避免不必要的版本请求。
各仓库可通过 stores[name].lazy 单独覆盖此值。
cache.memoryMax
| 类型 | 默认值 | 说明 |
|---|---|---|
number | 200 | 内存缓存最大条目数 |
cache.ttl
| 类型 | 默认值 | 说明 |
|---|---|---|
number | 0 | 内存缓存 TTL(毫秒),0 = 永不过期 |
cache.indexedDB.enabled
| 类型 | 默认值 | 说明 |
|---|---|---|
boolean | true | 是否启用 IndexedDB |
cache.indexedDB.dbName
| 类型 | 默认值 | 说明 |
|---|---|---|
string | 'nuxt-dict' | IndexedDB 数据库名称 |
locale.default
| 类型 | 默认值 | 说明 |
|---|---|---|
string | 'zh-CN' | 兜底语言 |
locale.source
| 类型 | 默认值 | 说明 |
|---|---|---|
'cookie' | 'header' | 'query' | 'cookie' | 语言检测来源 |
locale.cookieKey
| 类型 | 默认值 | 说明 |
|---|---|---|
string | 'i18n_redirected' | cookie 名称。默认值与 @nuxtjs/i18n 共享同一 cookie,实现语言自动同步。详见 i18n 国际化 |
locale.queryKey
| 类型 | 默认值 | 说明 |
|---|---|---|
string | 'lang' | URL 查询参数名 |
locale.paramKey
| 类型 | 默认值 | 说明 |
|---|---|---|
string | 'lang' | 发给 API 时语言参数的查询参数名 |
locale.apiHeaderKey
| 类型 | 默认值 | 说明 |
|---|---|---|
string | 'X-Locale' | 发给 API 时语言的请求头名 |
stores
| 类型 | 默认值 | 说明 |
|---|---|---|
Record<string, { baseURL?, dictEndpoint?, versionEndpoint?, adapter?, lazy? }> | {} | 多仓库 API 配置。每个仓库可配置独立的端点或自定义适配器 |
每个仓库的可配字段:
baseURL:API 基础地址,未配继承全局api.baseURLdictEndpoint:字典列表接口路径,未配继承全局api.dictEndpointversionEndpoint:版本号接口路径,未配继承全局api.versionEndpointadapter:该仓库的自定义适配器文件路径(string,不继承,未配则自动创建 REST 适配器)lazy:是否惰性检查版本号(boolean,未配继承全局api.lazy,默认false)
详见 多仓库。
ssr.prefetch
| 类型 | 默认值 | 说明 |
|---|---|---|
string[] | [] | 服务端预取的字典类型列表 |
详见 SSR 预取。
version.storageKey
| 类型 | 默认值 | 说明 |
|---|---|---|
string | '__NUXT_DICT_VERSION__' | localStorage 版本号 key |