Vetur 模板插值:如何通过 JsDoc 为模板设置全局虚方法?没有打字稿

Vetur template interpolation: How can I setup global virtual method for template by JsDoc? Without typescript

我在Nuxt注册了i18n。但是我可以毫无错误地使用它。插值没有看到 $t 方法。我该如何解决?

对于模板中的类型,我只使用 JsDoc

编译确实可以,但是我不想看到错误

错误: 属性“$t”在类型 'CombinedVueInstance<{ openedSubMenuId: any; } & { openSub(id: any): void; closeSub(): void; } & { nav: NavItem[]; value: boolean; } & Vue, object, object, object, Record<never, any>>'

上不存在

Nuxt 配置

export default {
  head: {
    title: 'nuxt-football',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  },

  css: ['@/assets/scss/_vars.scss', '@/assets/scss/main.scss'],

  styleResources: {
    scss: ['./assets/scss/*.scss'],
  },

  plugins: [],

  components: {
    dirs: [
      '~/components',
      {
        path: '~/components/App/',
      },
    ],
  },

  buildModules: ['@nuxtjs/eslint-module'],

  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/pwa',
    '@nuxtjs/style-resources',
    'nuxt-i18n',
  ],

  i18n: {
    defaultLocale: 'ru',

    locales: [
      {
        code: 'ru',
        file: 'ru-Ru.js',
      },
    ],
    lazy: true,
    langDir: 'lang/',
  },

  axios: {},

  build: {},
};

你需要将它添加到tsconfig(如果你使用的是nuxt):

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