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

310
Vistas
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 Respuestas
Responde la pregunta

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 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