how to call api with id vue js i'm trying to call my api url/api/notification/{{id}} in vue js.
My browser URL is already http://192.168.0.130:8080/notification/6 .
Problem is, I'm not getting my id(consol error).
What can I do?
Vue.axios.get('url/api/notification/${notice.id}')
This is not working also
If you want to use string interpolation, you need to use backticks:
Vue.axios.get(`url/api/notification/${notice.id}`)
Is the URL correct?
@tykus
my router
{
path: "/notification/:id",
name: "Chat",
meta: {
auth: true
},
component: Chat
},
Current URL
http://192.168.0.130:8080/notification/6
the console error
url/api/%60/api/notification/$%7Bid%7D%60
still doesn't fetch the id
@tomasosho this is URL encoding of
url/api/`/api/notification/${id}`
So wherever you are making the XHR request; the URL is screwed up. Are you running npm run dev whenever you are changing the JS source?
@tykus :to="`/notification/${item.id}`"
then to router
{
path: "/notification/:id",
name: "Chat",
meta: {
auth: true
},
component: Chat
},
@tomasosho but the console error is still url/api/%60/api/notification/$%7Bid%7D%60???? The code you're sharing and the error message are not making sense...
@tykus can i share my repository link with you?
@tomasosho you can... but I can't look at it until morning.
@tykus so i fixed the link but I'm getting /api/notification/undefined 500 (Internal Server Error)
Vue.axios.get(`/notification/`+this.id)
This works
Vue.axios.get(`/notification/`+this.$route.params.id)
I have one action which makes a call to API on success I call a mutation with data.
Vue Component
this.$store.dispatch('AxiosAction'',{ action : 'getuser' , id : 1} }
state :{
axiosActions : {
'getuser' :{
url : '/getuser'
}
}
}
Vuex Action
AxiosAction(data) {
url = mainurl + state[data.action].url
axios()
then() {
this.commit(data.action , response)
}
}
Vuex Mutation
getuser(data) {
state.user = data
}
Bases on the action, https://echat.date i get the URL for the Endpoint
Please sign in or create an account to participate in this conversation.