0

I´m trying to do a function in the method with vuejs 2 and call this function inside mounted() but it returns- Error in the mounted hook: "TypeError: this.getFormula is not a function"

I´m doing an apollo query in this method to fill one array and return data to my component.

mounted() {
    if (this.$route.params.id_tipo_liquidacion) {
      this.tipoLiquidacion_id = this.$route.params.id_tipo_liquidacion;
      this.grupoId = Number(this.$route.params.id_agrupacion);
    }
    if (this.$route.params.id_tipo_seccion_liquidacion) {
      this.tipoSeccionLiquidacion_id = this.$route.params.id_tipo_seccion_liquidacion;
      this.grupoId = Number(this.$route.params.id_agrupacion);
    }

    this.getFormula()
  },
  method: {
    getFormula: () => ({
        fetchPolicy: 'cache-and-network',
        query: gql`query formulas($id: ID!){
                        formula(id: $formula_id){
                                myDBdata
                        }
                    }`,
        variables() {
          return {
            id: parseInt(myBeforeArray.id),
          }
        },
      }).then(response => {
        this.formula = response.data

        console.log(this.formula)
      })
      .catch(error => {
        console.log('Error-> ');
        console.log(error);
      })
  })
}

And the problem it´s that I can´t call my function.

UPDATE-

After the response @Mati y has this problem now:

Error in the mounted hook: "TypeError: {(intermediate value)(intermediate value)(intermediate value)}.then is not a function"
Neha Soni
  • 3,935
  • 2
  • 10
  • 32
scorpions78
  • 553
  • 4
  • 17

0 Answers0