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

208
Visualizações
Open window in new tab after async api call

I have this function I want to call followed by the opening of a page in a new tab after a user clicks an element in my VueJS application similar to this:

const someFunction = async () => {
   const value = await api.someCallToApi();
   window.open('https://example.com', '_blank').focus();
}

I am not allowed to do this, probably due to the await resulting in the window.open not being a direct result of a user action(?)! Due to the way my application is setup the order of the api call and opening of the window in the new tab is relevant.

What would be a solid and modern way of tackling such an issue?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In an ideal world, all asynchronous functions would already return promises. But there may be still old libraries that use await. You can create a Promise that wraps the await function as below:

const delay = (ms) => new Promise(resolve => setTimeout(resolve.bind(null, ms/1000), ms));


delay(3*1000).then((sec) => alert(sec + " seconds passed"));

about 4 years ago · Juan Pablo Isaza 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