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

312
Visualizações
Axios Vue: undefined post parameters in express server but defined in Vue

I have an <img> element like this:

<img v-bind:word = "thing" @click="action" align="center" src="../assets/pic.png"/>

and a method like this:

 async action() {
      let imgAttribute = event.target.getAttribute('word');
      alert(imgAttribute ); // alerts OK
      console.log("imgAttribute : " + imgAttribute ); // prints OK

     await axios.post('http://localhost:3000/my/endpoint',
         {
           params: {
             word: imgAttribute 
           }
         });
...

So when the <img> element is clicked, the method action is executed. The word attribute is taken and put in imgAttribute variable, which is then passed as a parameter in the post request.

alert(imgAttribute) and console.log(imgAttribute) work fine, which means they don't print undefined, but print correct string values that are inside word attribute.

However on Express server:


app.post('/my/endpoint', async (req, res) => {
    const {word} = req.params;  // tried req.query with the same (undefined) result
    console.log("word = " + word); // undefined
...

The word is undefined.

Why does it happen? How do I fix it?

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

0

You passed as body via .post, to pass as params use

  await axios({
    url: 'http://localhost:3000/my/endpoint',
    method: 'post',
    params: {
        word: imgAttribute 
    }
  })
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