Updating locale in Vue-i18n does not result in complete refresh of all components

Just diving into vue-i18n, it looks promising but facing some difficulties in getting it to function properly.

Changing the locale updates all template translations correctly, however when

script

data() {
  return {
    locales: {
      en: this.$i18n.t('topnav.lang.english'),
      da: this.$i18n.t('topnav.lang.danish'),
      sw: this.$i18n.t('topnav.lang.swedish'),
      no: this.$i18n.t('topnav.lang.norwegian'),
    }
  }
},

template

WORKING

{{$t('topnav.lang.english')}}

NOT WORKING

<a class="dropdown-item">{{locales.en}}</a>

NOT WORKING

<a class="dropdown-item" @click="changeLocale(key)" v-for="(value, key) in locales">{{value}}</a>

I've experimented with various approaches, such as lazy loading language files, but still unable to resolve it.

Answer №1

Switch from using data to computed properties since data is not inherently reactive but computed is!

If you prefer, you can also directly insert your translation into the template instead of utilizing computed properties.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for aligning a cluster of floating buttons at the center in Vuetify:

This is the code I am currently working with: <v-container height="0"> <v-row align="center" justify="center"> <v-hover v-slot:default="{ hover }" v-for="(option, index) in options" ...

Error encountered while attempting to retrieve an environment variable: Invalid token found

I am currently facing an issue while trying to add an environment variable inside the .env file in my Nuxt project. The version of Nuxt.js I am using is 2.15.3 Below is a snippet from my nuxt.config.js: export default { publicRuntimeConfig: { baseU ...

Determine the HTTP status code for a request using Vue.js and Ajax

I need to retrieve the HTTP status code after submitting a form (using the form submission function): return fetch(serviceUrl + 'Collect', { method: "POST", headers: new Headers({ "Content-Type": "application/json", Authoriza ...

What could be causing my router link tag to malfunction within the bootstrap framework?

In my project, I am using vue.js in combination with bootstrap to develop a navigation task bar for the frontend. To set up the routing functionality, I have created a separate file called router.js. router.js import Vue from 'vue' import Router ...

Is there a way for me to showcase the latitude and longitude retrieved from JSON data on a Google Map using modals for each search result in Vue.js?

After receiving JSON data with search results, each containing latitude and longitude coordinates, I am attempting to display markers on a Google map modal when clicking "View Map". However, the code I'm using is not producing the desired outcome. Th ...

Is there a way to differentiate between a browser application running on a local development server and an online staging server?

Is there a way to conditionally call a component only on the staging server and not on the local machine in Vue.js? <save-drafts-timer v-if="!environment === 'development'" /> ... data () { return { environment ...

A guide on incorporating Vue.js into a Hexo static site generator

Exploring the use of vue.js within my hexo theme has sparked my interest. Can anyone guide me on how to compile my .vue files for both development and production environments? It's worth mentioning that I intend for vue.js to operate on the client sid ...

Is there a way for me to activate the button upon clicking on a box in the list?

I found my inspiration from the following sources: Below is how my vue component looks like: <template> ... <b-card-group deck v-for="row in formattedItems"> <b-card :title="item.title" img-src=" ...

Troubleshooting: Passing data from child to parent component in Vue causing event malfunction

This is a custom component created by Jobs that triggers an event to its parent component. <div class="card py-1 my-1" @click="$emit('active-job', job.id, job.slug)"></div> The parent component is set up to listen ...

Tips for aligning a button to the bottom of a card in Vuetify, regardless of the text length

I'm having trouble aligning buttons in my cards. I have a layout with 3 cards in a row, but the button's position changes when text is added to a specific card. I've tried passing different props and using various classes, but nothing seems ...

Is the popup not opening with just one click?

https://i.stack.imgur.com/09dcf.png Upon clicking the first input cell, the popup opens and closes as expected. However, when closing the initial input and opening another one, an orange mark icon appears but the popup doesn't open until the second c ...

What is the process for updating the Vue template during runtime?

Currently, I am working on a CMS-based Vue page. Within this page, there is a root container that contains two child containers structured as follows: <div id="app"> <div class="above-the-fold">...</div> <di ...

Having an issue with Vue-loader where it's throwing an error for an unexpected

After executing the webpack command, I encounter an unusual error within the vue-loader library. ERROR in ...\node_modules\vue-loader\lib\parser.js:25 output.styles.forEach(style => { ^^ Unexp ...

Can Vue.js support two-way data-binding without the use of an input element?

Here is the code snippet that I'm working with: <div id="app"> {{ message }} </div> JavaScript: myObject = {message:"hello"} new Vue({ el: '#app', data: myObject }) When I update myObject.message, the content within th ...

receiving a response within an HTML tag using Vue.js

Could someone assist me with retrieving data in an HTML tag similar to how I can do it with console.log? I am trying to get the value console.log(this.likeDes[0].like_dislike) to display within a <span class="fa fa-heart-o"></span> ...

Creating a combinational chart with varying data values using Echarts in Vue.js

In my VueJS application, I am facing a challenge while using Echarts to visualize data. The issue arises when I try to create an echart with multiple series that have different numbers of values in their data objects. EChart requires all series objects to ...

What could be causing my Nuxt/vue pages to be blocked by the robot.txt file?

This isn't a query about SEO best practices, but rather a question on correctly setting up config.js and script sections in VUE After building my site with Vue/Nuxt, which was previously easy for me with Angular, I am now encountering errors. The ma ...

Implementing bidirectional data binding with Semantic UI's search dropdown feature in Vue.js

I'm currently facing an issue with the Semantic-UI searchable dropdown and Vuejs data binding. It seems like only one changed option is being model-bound, no matter which dropdown option I select. Here's a snippet of my code. I attempted to use ...

Guide on creating an alias in webpack within vue-cli4?

Is there an alternative method for setting the alias in vue-cli4 since there is no webpack.base.conf.js file? Thank you! ...

The Vue.js QueryBuilder from Cube.js is designed to enhance data privacy by allowing columns to be anonym

In my current situation, I am facing a unique challenge involving multiple clients for a single user. Each client generates different reports based on their specific client id (which is easy to filter). However, there is a requirement to anonymize certain ...