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

230
Views
How to make function and loop in VUE correctly?

I want to write in VUE as well as js or jquery but this framework have some secrets i do not discover yet. I want to make simple loop for and function but i can just make the simplest calculation. I write somethink like that and this calculator work perfect:


data: {
    pv: {
      p: '',
      pd: '', 
      d: '',
      u: '',
      w: '',
    
   },
  },
  methods: {
    calc: function () {
    var d = this.pv.d
    var p = this.pv.p
    var u = this.pv.u
        var w = this.pv.w
  this.pv.pd = p - d; 
this.pv.w =  this.pv.pd - u;

},

but i want to have something more advance:

this.pv.w = function(){if(w < 1000){return 1000-u;}else{w-u;}}

in simple js it would work perfect but i do not understand VUE framework as well. Or a loop for

this.pv.w = function(){for(i=0;i<10;i++){var s = u*i;}}

This is easy task i do not find in their documentation

just find that loop is {{n in 50}} but i want have calculation od "js side" then put in to html dom if i want to.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Some hints on how to use the variables in vue:

  data() return {
    pv: {
      p: '',
      pd: '', 
      d: '',
      u: '',
      w: '',
   },
  },
  methods: {
    calc1() {  // no function keyword required
      let pv = this.pv;  // shorthand
      pv.d = pv.p - pv.d; 
      pv.w =  pv.pd - pv.u;
    },
    calc2() {
      let pv = this.pv;
      if(pv.w < 1000){
        pv.w = 1000 - pv.u;
      } else {
        pv.w = pv.w - pv.u;
      }
    },
    calc3() {
      let pv = this.pv;
      for(let i=0; i<10; i++){
        pv.w += pv.u*i;
      }
    }
about 4 years ago · Juan Pablo Isaza Report
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!