我尝试在以下组件的ts
文件中使用ts
:
export default class MyComponent extends Vue {
readonly i18nTitle = this.$t('translation.key');
//...
}
但我知道错误是:
TypeError:无法读取未定义堆栈溢出的属性“_t”
这个错误只在我尝试在i18n
文件中使用ts
时发生,但是当我在html
中使用它时,它会很好地工作。
我对i18n
的配置是非常基本的:
// 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/>',
});
知道我错过了什么吗?
发布于 2020-10-16 11:35:06
玩了一会儿之后,我发现如果我使用一个吸气器,它就能工作。
我就是这样从ts
文件中翻译文本的:
export default class MyComponent extends Vue {
get i18n() {
return {
title: this.$t('translation.key');
};
}
}
并在html
中这样使用:
<h1>{{i18n.title}}</h1>
https://stackoverflow.com/questions/64395333
复制相似问题