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

160
Visualizações
Vue computed property updates without dependency change

I made a computed property to sort a Javascript object alphabetically by key. I added logging to the computed property to make sure that it was not being invoked without a dependency change.

I found that without changing the reactive dependency (sensorData), the computed property seems to reevaluate at a high rate (10+ Hz).

Why is it reevaluating without a dependency change?

What I've Tried

I know that Vue recommends against property addition/deletion, and my object is initialized to {}. However, even when initializing it with every key, I had the same result.

I also tried vm.$set(object, key, value) as recommended if properties need to be added after a page is rendered. No luck.

JSON from Server

{
  "readings": {
    "stepperC": 180,
    "stepperA": 360,
    "stepperB": 0
  }
}

Vue Code

data: () => ({
  sensorData: {}
}),
computed: {
  // sort alphabetically by key
  sortedSensorData() {
    console.log("calling sort");
    return Object.keys(this.sensorData).sort()
      .reduce((obj, key) => ({
        ...obj,
        [key]: this.sensorData[key]
      }), {});
  }
}
methods: {
  handleWebSocketMessage({ data }) {
    const newReadings = data.readings;
    if (Object.entries(newReadings).some(([sensor, reading]) => this.sensorData[sensor] !== reading))
      this.sensorData = newReadings;
  }
}

Output

With no change to sensorData:

calling sort
calling sort
calling sort
...
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