我使用插件vue-i18n在Nuxt.js驱动的SPA中进行翻译。这允许轻松访问组件中的消息,如下所示:
$t('footer.press')但是如何获得外部组件的翻译呢?在我的具体情况下,我需要在商店操作中使用它们:
export const actions = {
async myAction({ commit, state, rootState, rootGetters }, options) {
(...)
const message = $t("example.message.key") // doesn't work, undefined
const message1 = this.$i18n.t("example.message.key") // doesn't work, undefined
(...)
})
}这就是我如何将vue-i18n插件包含在项目中的方式:
package.json
…
"dependencies": {
…
"vue-i18n": "^8.18.2",
…
},
…nuxt.config.js
…
plugins: [
…
'~/plugins/i18n',
…
],
…发布于 2020-12-17 09:17:23
发布于 2022-05-31 13:54:15
this.$t('logInWongCredentials')(努xt)
https://stackoverflow.com/questions/65337742
复制相似问题