我的问题有点具体。我在这个项目中使用 Vuex 和 Nuxt。对于依赖项,我们使用 i18n-nuxt 但不知何故我无法在 $store 中使用 $t('some.translation') 而在组件中它工作得很好。我尝试了所有我能想到的可能组合,但结果仍然导致我犯同样的错误。
ReferenceError $t is not defined
orCannot read the property of i18n
所以在这种情况下,我可以使用一些帮助来解决这个问题,或者如果有人向我展示如何使用 i18n 作为过滤器,那将是完美的。 (我认为这是唯一的解决方法。)
例如这个代码块来自$store.state
sortMethods: [
{ id: 'airline', name: this.i18n.$t('Airline'), asc: 'A', desc: 'Z', defaultDirection: 'asc' },
你可以想象我无法在原地翻译它们。
最佳答案
可以在 this.$i18n.t
的突变和操作中使用 t
。例如:
export const mutations = {
foo() {
console.log(this.$i18n.t("bar"));
}
}
但是我还没有找到在 state 或 getter 中使用它的方法,因为它们无权访问 this
。
关于vue.js - 在 Vuex 商店中使用 i18n-nuxt $t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65488981/