Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda