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

365
Visualizações
Nuxt - getter for window innerwidth does not update

Our project uses class based components. I have a getter to get the window innerWidth, but the value is only set once, it doesn't update if I change the window width.

get viewPortWidth() {
  
    if (process.client) {
          if (window.innerWidth !== undefined && window.innerHeight !== undefined) {
            return window.innerWidth;
          } else {
            return document.documentElement.clientWidth;
          }
        }
        return false; 
  }

If I write the value in the html: {{viewPortWidth}} it doesn't change. The value is the same also in vue devtools. Aren't getters supposed work like computed properties? How can I get to update seamlessly?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

vue computed properties are cached based on their reactive dependencies. window.innerWidth not a reactive dependency.

you can track changing window size event by adding an event listener in your "created" lifecycle hook like this:

created(){window.addEventListener('resize', (e)=>{console.log(e)})}
about 4 years ago · Juan Pablo Isaza Relatório
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