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

189
Views
Create a reactive Proxy with VueJs

I'm working on a little project where I implemented a simple versioning system.
I have an array of objects (the diferent versions) that I wrap in a Proxy which will give me the informations of the desired version.

I use this object in a VueJs component and would like the view to be reactive when I change the version property of the Proxy.
How could I manage that ?

So far, to do so, I forgot about the proxy idea and just used a computed property. But I'd like to keep my Proxy for aesthetic reason.

Here is a simplified version of what I'd like

function versioning (versionArray) {
  return new Proxy(versionArray, {
    version: 0,
    latest: versionArray.length - 1,
    get: function (target, prop) {
      if (["version", "latest"].includes(prop)) {
        return this[prop];
      } else {
        return target[this.version][prop];
      }
    },
    set: function (target, prop, val) {
      if (prop === "version") {
        return this.version = val;
      } else {
        return false;
      }
    }
  })
}

let myData = versioning([
  { 
    title: "My title",
    description: "My first desption" 
  },
    { 
    title: "THE title",
    description: "My first description" 
  },
  { 
    title: "THE title",
    description: "It's a nice description" 
  }
]);
myData.version = myData.latest;

Vue.createApp({
  data() {
    return {
      myData,
    }
  },
  methods: {
    version(val) {
      this.myData.version = Math.min(Math.max(this.myData.version+val, 0), this.myData.latest);
    }
  }
}).mount('#app');
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.31/vue.global.prod.min.js"></script>
<div id="app">
  <button @click="version(1)">
    &lt;&lt;
  </button>
  <div>{{myData.title}}</div>
  <div>{{myData.description}}</div>
  <button @click="version(-1)">
    &gt;&gt;
  </button>
</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!