首頁  >  問答  >  主體

Vue 3 組合式 API 的 i18n 本地化未更新

<p>我正在嘗試透過點擊按鈕來更改Vue-i18n的區域設定。但是當我點擊按鈕時,什麼都沒有發生。也沒有任何錯誤。如何解決這個問題? </p> <pre class="brush:php;toolbar:false;"><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; };</pre> <p><br /></p>
P粉752826008P粉752826008396 天前374

全部回覆(1)我來回復

  • P粉550823577

    P粉5508235772023-08-26 00:14:37

    可能還有其他問題,但程式碼中至少有一個錯誤。 i18n.global.locale 是一個 ref,應該使用以下方式:

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

    它不能以反應性的方式進行。

    回覆
    0
  • 取消回覆