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

138
Vistas
accessing `this` inside async functions in methods of vue.js

I have a vue.js class method that needs to call on an async function using await:

methods: {
   playRecording(path) {
      return await this.getAudioUrl(path)
   }
}

This results in the following error:

Unexpected reserved word 'await'.

In order to fix this error, I re-wrote the code using async as such:

methods: {
    playRecording : async() => {
       console.log(this) // `this` evaluates to `undefined`
       var path = '/recordings/' + this.book
       return await this.getAudioUrl(path)
    }
}

While this does address the await error above, it results in a new error:

Cannot read properties of undefined (reading 'book')

this evaluates to undefined

How can I regain access to this inside a class method marked with async?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The calling method has to be defined as such:

async playRecording () {

This is incorrect:

playRecording : async() => {
about 4 years ago · Santiago Gelvez 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