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

195
Visualizações
Vue dispaly audio file fetched from Express backend: audio/mp3

express endpoint:

app.get('/test', (request, response) =>  {
    response.sendFile("/absolute/path/to/file/myfile.mp3");
});

Test.vue:

<template>
  <div>
    <p>test {{text}}</p>
    <audio controls="controls" src="./myfile.mp3">

    </audio>
  </div>

</template>

<script>

import axios from "axios";

export default {
  name: 'Test',

  data: function ()  {
    return  {
      text: 'hello',
      audio: ""
    }
  },

  created() {
    this.$watch(
        () => this.$route.params,
        () => {
          alert("fetching")
          this.fetchData()
        },
        
        { immediate: true }
    )
  },

  methods:  {
    fetchData()  {
      axios.get('http://localhost:3000/test',
          {
            params: {

            }
          })
          .then((response) => {
             alert("done")
             alert(JSON.stringify(response));

             const url = URL.createObjectURL(response);


             alert(url);
          });
    }
  }
}
</script>

When I load the Test.vue I get:

first alert:

enter image description here

second alert:

enter image description here

third alert:

enter image description here

and then the page appears:

enter image description here

I know I need to connect the received response from express to the <audio> element, but I'm not sure how. And I noticed that alert(url) is never displayed (no alert window appears).

Express is at localhost:3000 and Vue is at localhost:8080. When I go to http://localhost:3000/test, I get the page with the playable audio file, so express backend does its job:

enter image description here

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