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

285
Visualizações
vuejs (3) update view from a self changing class

Basically i would like to have my class (changer) take care of its own state, and when it want trigger Vue to update everything depending on the public fields.

When I am using a method it does work however the timer doesn't

From the Vue sources, it seems that i could achive this by running the trigger function like this

trigger(target, \"set\" /* SET */, key, value, oldValue);

https://unpkg.com/vue@3.2.19/dist/vue.global.js #875

However the trigger function is not exported from vue and doesn't seem to be made to be used manually, is there another way? or the only way is to go and set all the way deep from the app2 object?

class changer {
  constructor() {
    this.value = 0
    setInterval(() => {
      console.log(this,this.value)
      this.value++
    }, 2500)
  }

  changeme() {
    this.value++
      //tell vue to trigger values dependicies
  }


}

var c = new changer();

c.changeme();
console.log(c);
var m = new Map();
m.set("a", 1);
m.set("b", 1);
console.log(m);

var Counter = {
  data() {
    return {
      counter: 0,
      m,
      c
    }
  },

}

var app = Vue.createApp(Counter);
var app2 = app.mount('#counter')
<script src="https://unpkg.com/vue@next"></script>

<div id="counter">
  Counter: {{ counter }}
  <span v-for="i in  m">{{i}}</span>
  <button @click="m.set('a',2)">Change Map</button>
  <span>
    {{c}}
    <button @click="c.changeme()">Change with method</button>
    <button @click="c.value++">Change with set</button>
  </span>
</div>

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