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

163
Views
no se puede presionar el método vue desde la respuesta de axios

No puedo entender qué está mal aquí, pero mi llamada axios funciona correctamente y mi respuesta de datos regresa como esperaba con éxito.

El problema ahora es cuando trato de llamar a otro método vue dentro de mi respuesta exitosa de axios. Si comento la llamada al método, entonces está bien, pero si lo dejo, la consola solo lee indefinido y no obtengo el archivo console.log desde dentro de mi función de prueba, por lo que parece que ni siquiera lo estoy presionando.

¿Qué he hecho mal?

 var vm = new Vue({ el: "#app", methods: { axiosFunc() { axios({ method: 'post', url: test, data: { date:'2022-03-02', } }).then(function (response) { console.log('success'); this.testFunction(); }).catch(function (error) { }); }, testFunction() { console.log('in new function'); } } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <button @click="axiosFunc()">Console log</button> </div>

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

0

Reemplace su

 ... .then(function (response) { console.log('success'); this.testFunction(); }) ...

por

 ... .then(response => { console.log(response); this.testFunction(); }) ...

Para evitar la anulación del contexto.

También puedes usar este código:

 ... .then(function (response) { console.log(response); this.testFunction(); }.bind(this)) ...

O

 ... const that = this; ... .this(function (response) { console.log(response); that.testFunction(); }) ...
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!