i18n localization for Vue 3 composition API not updated
P粉752826008
2023-08-25 14:11:14
<p>I'm trying to change the locale for Vue-i18n by clicking a button. But when I click the button, nothing happens. There are no errors either. how to solve this problem? </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>
There may be other issues, but there is at least one bug in the code.
i18n.global.locale
is a ref and should be used as follows:It cannot be done in a reactive manner.