Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda