Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda