【问题标题】:Vue 3 i18n Locale Not Updating (Composition API)Vue 3 i18n 语言环境未更新(组合 API)
【发布时间】:2021-10-07 04:11:36
【问题描述】:

我正在尝试通过单击按钮来更改 Vue-i18n 语言环境。但是当我点击按钮时,什么也没发生。也完全没有错误。如何解决这个问题?

<button v-on:click.prevent="setLocale('id')">Ind</button>
<button v-on:click.prevent="setLocale('en')">Eng</button>

import i18n from "../i18n";
const setLocale = (lang) => {
  i18n.global.locale = lang;
};

【问题讨论】:

  • 在初始化 app.ts 时是否添加了 i18n 配置?
  • @DFXNguyễn 是的 createApp(App).use(i18n)
  • 没有足够的上下文来确定问题。 i18n.js 中有什么内容?
  • 请提供可以重现问题的stackoverflow.com/help/mcve。您发布的稀缺 sn-p 不可行,并且不显示相关内容。错误的一件事是i18n.global.locale

标签: vue.js vue-i18n


【解决方案1】:

可能还有其他问题,但代码中至少有一个错误。 i18n.global.locale is a ref 应该用作:

const setLocale = (lang) => {
  i18n.global.locale.value = lang;
};

它不能以其他方式反应。

【讨论】:

    猜你喜欢
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 2021-08-15
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多