I'm developing an app in Vue using Vue Routers and Vue $i18n plugin.
This is my HTML:
<div class="locale-changer">
<select v-model="this.$i18n.locale" class="btn">
<option v-for="(lang, i) in langs" :key="`Lang${i}`" :value="lang">{{ lang }}</option>
</select>
</div>
And my JS:
export default {
name: "home",
data() {
return {
langs: ['Español', 'English'],
currentlang: this.$i18n.locale
}
},
mounted() {
if(localStorage.currentlang) this.currentlang = localStorage.currentlang;
},
watch: {
currentlang(newLang) {
localStorage.currentlang = newLang;
}
}
};
I have already searched the Internet but still cannot get it.
Hope you can help me! Thanks <3