I'm working on a Vue app that utilizes Vue Routers and the Vue $i18n plugin.
Here's how I've structured 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 here is the JavaScript code:
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've been scouring the web for solutions but haven't found one that works for me.
I hope someone here can assist me! Much appreciated <3