[Vuejs]-How to solve VueJS calculator working once?

0👍

The problem:

precedente() is a method, but you are changing it to a variable and setting it as null in two places, which is breaking the code that then tries to call it as a method.

  1. Inside the precedente() method with this.precedente = this.numCorrente;
  2. Inside uguale() method with this.precedente = null;

To fix:

Change the name of the variable wherever you use this.precedente (without the two () brackets) to a different name.

For example, change it to precedenteNum:

precedente() {
    this.precedenteNum = this.numCorrente; // changed | cambiato
    this.cliccato = true;
},

uguale() {
    if (this.operazione) {
        this.numCorrente = `${this.operazione} = ${this.numCorrente}`;
        this.operazione = '';
    } else {
        this.numCorrente = `${this.operatore(
            parseFloat(this.precedenteNum), // changed | cambiato
            parseFloat(this.numCorrente)
        )}`;
    }
    this.precedenteNum = null; // changed | cambiato
},

Leave a comment