首页 > 解决方案 > Typescript & nuxt:i18n 类型不起作用

问题描述

我在 typescript 中使用nuxtjs / i18n并且我在TS config中添加了它的类型

{
  "compilerOptions": {
    "types": [
      "@nuxt/types",
      "@nuxtjs/i18n",
    ]
  }
}

但是在我想使用的组件中

this.$i18n.locales

我有这个错误

在此处输入图像描述

在此处输入图像描述

那么,如何修复 @nuxt/i18n 的类型错误?

标签: typescriptvue.jsnuxt.jsvue-i18nnuxt-i18n

解决方案


尝试这样的事情:

import { LocaleObject } from '@nuxtjs/i18n'
...
(this.$i18n.locales as LocaleObject[])

推荐阅读