I want to send a request to http://localhost:5000/trackers/{{id}}. I tried to pass parameters through axios, but when i checked the API the request went only to http://localhost:5000/trackers/. How can I fix this?
Axios code:
mounted() {
axios.get('http://localhost:5000/trackers/', {params : { id } })
.then((resp ) => console.log(resp.data))
.catch((err) => console.log(err.response))
let id = localStorage['id']
return{
id
}
How to pass the query parameters through axios This is my API code: I still haven't created a route for '/trackers/{{id}}' in my API. I first tried to check if the routing in my VueJS code is working.
CodePudding user response:
If you just need to request http://localhost:5000/trackers/{{id}}
,
you can build the request url like this:
...
axios.get('http://localhost:5000/trackers/' id)
...
CodePudding user response:
Can you try once with the following code?
mounted() {
axios.get(`http://localhost:5000/trackers/${id}`)
.then((resp ) => console.log(resp.data))
.catch((err) => console.log(err.response))
let id = localStorage['id']
return{
id
}
}