i18n localization for Vue 3 composition API not updated
P粉752826008
P粉752826008 2023-08-25 14:11:14
0
1
369
<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>
P粉752826008
P粉752826008

reply all(1)
P粉550823577

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:

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

It cannot be done in a reactive manner.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!