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

198
Views
Vue js: problema de espera asíncrona

Mi código en Login.Vue es el siguiente

 methods: { async validateLoginBeforeSubmit () { this.$validator.validate().then((result) => { if (result) { var data = { email: this.email, password: this.password } var response = await this.$api('POST', 'login', data); } }) }, },

y esta es la función prototipo

importar Vue desde 'vue';

 Vue.prototype.$api = async() => function(method, url, data){ if (method == 'POST') { return new Promise((resolve) => { this.$http.post(url, data).then((response) => { resolve(response); }).catch((error) => { if (error.response.status == '401') { /* Destroy token from local storage and redirect to login page */ } resolve(error.response); return false; }); }); } }

Está arrojando debajo del error

 error Parsing error: Unexpected reserved word 'await'.

¿Alguien puede ayudarme con lo mismo?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No debe mezclar y combinar async/await y tradicional y then prometer el manejo, ya que puede causar confusión.

Intente intentar:

 async validateLoginBeforeSubmit () { var result = await this.$validator.validate() if (result) { var data = { email: this.email, password: this.password } var response = await this.$api('POST', 'login', data); } }
about 4 years ago · Santiago Trujillo 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!