[Vuejs]-How to call URL in axios.post request for get data each id?

-1👍

What you need is to create a route for the single page that has params in it, and parse them in the component to use them in the request.

See: https://router.vuejs.org/guide/essentials/passing-props.html

Register your routes with the desired component and specify a parameter:

{ path: '/user/:book_id', component: require("<singlepage.vue>"), props: true }

singlepage.vue:

<template>

   <div class="content">
       <div class="content-sidebar">
       <SideBar />
       </div>
       <section class="main-content">

         <div class="content-container">
             <div class="content-img"> <img src="" alt=""></div>
             <div class="content-text" >
                 <h2></h2>
                 <p></p>
             </div>
         </div>
       </section>
    
   </div>


</template>

<script>
import axios from 'axios'

import SideBar from '../../components/Sidebar.vue'

export default {
components :{
    SideBar
},
props: ["book_id"],
//I have a problem here//
setup() {
   const request = { RequestID : "16460"}
    function getContent (){
  axios.post('request url', request ,
  { headers : {
          'Content-Type' : 'application/json',
      }}
  )
  
    .then(function(response){
        console.log(response);
    })
}
 getContent();
 return {};
    }
   
}
</script>
👤ryuk

Leave a comment