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

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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