Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 Respostas
Responde à pergunta

0

The calling method has to be defined as such:

async playRecording () {

This is incorrect:

playRecording : async() => {
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda