Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
Axios Vue: parámetros de publicación indefinidos en el servidor express pero definidos en Vue

Tengo un elemento <img> como este:

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

y un método como este:

 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 } }); ...

Entonces, cuando se hace clic en el elemento <img> , se ejecuta la action del método. El atributo de la word se toma y se coloca en la variable imgAttribute , que luego se pasa como un parámetro en la solicitud posterior.

alert(imgAttribute) y console.log(imgAttribute) funcionan bien, lo que significa que no imprimen undefined , pero imprimen los valores de cadena correctos que están dentro del atributo de la word .

Sin embargo, en el servidor Express:

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

La word es indefinida.

¿Por que sucede? ¿Cómo lo soluciono?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pasaste como cuerpo a través de .post, para pasar como uso de parámetros

 await axios({ url: 'http://localhost:3000/my/endpoint', method: 'post', params: { word: imgAttribute } })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!