首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Vue i18n TypeError:无法读取未定义的属性“_t”

Vue i18n TypeError:无法读取未定义的属性“_t”
EN

Stack Overflow用户
提问于 2020-10-16 19:35:06
回答 1查看 3K关注 0票数 0

我尝试在以下组件的ts文件中使用ts

代码语言:javascript
代码运行次数:0
运行
复制
export default class MyComponent extends Vue {
  readonly i18nTitle = this.$t('translation.key');

  //...
}

但我知道错误是:

TypeError:无法读取未定义堆栈溢出的属性“_t”

这个错误只在我尝试在i18n文件中使用ts时发生,但是当我在html中使用它时,它会很好地工作。

我对i18n的配置是非常基本的:

代码语言:javascript
代码运行次数:0
运行
复制
// i18n/index.ts
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import fr from './translations/fr.json';

Vue.use(VueI18n);

export const i18n = new VueI18n({
  locale: 'fr',
  fallbackLocale: 'fr',
  messages: {
    fr,
  },
});

// maint.ts
import { i18n } from './i18n';

new Vue({
  el: '#app',
  i18n,
  components: { App },
  template: '<App/>',
});

知道我错过了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-16 19:35:06

玩了一会儿之后,我发现如果我使用一个吸气器,它就能工作。

我就是这样从ts文件中翻译文本的:

代码语言:javascript
代码运行次数:0
运行
复制
export default class MyComponent extends Vue {
  get i18n() {
    return {
      title: this.$t('translation.key');
    };
  }
}

并在html中这样使用:

代码语言:javascript
代码运行次数:0
运行
复制
<h1>{{i18n.title}}</h1>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64395333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档