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

284
Views
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
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!