Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
Set global dayJs locale at Nuxt SSR

This only doesn't work when rendered server side!

I've got the problem, that dayJs doesn't update the locale globally after loading a page. While i18n works fine, dayJs doesn't update there.

In fact it switches to the locale for 1 second but then switches back to the defaultLocale set in the nuxt.config.js.

  async fetch() {
    const res = await this.$apollo.query({
      query: eventSeriesBySlug,
      variables: {
        'slug': this.$route.params.slug
      }
    });

    this.eventSeries = res.data.eventSeriesBySlug;

    // "en" or "de"
    this.locale = this.eventSeries.language.short;
    
    // i18n works
    this.$i18n.setLocale(this.locale);

    // does just update when rendered client side 
    this.$dayjs.locale(this.locale);
  }

I tried a watcher:

 watch: {
    locale(data) {
      this.$dayjs.locale(data);
    }
  },

It didn't change (although the watcher is called). It only works with setting the locale locally like:

this.$dayjs(event.dateStart).locale(this.locale).format('MMM')

But to save this locale in a store or pass it through all components isn't really a solution I would prefer. So any ideas on this?

And again: this only happens on rendered server side. When I navigate to the page by a nuxtlink / hot reloading is happening (so client side rendering) it's fine.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!