Answer the question
In order to leave comments, you need to log in
How to make vue axios dynamic url?
Good afternoon.
I need to make an API call to Laravel, passing the post id in the URL. How can I pass it to axios? Below is an example of my code.
import axios from 'axios';
export default {
data(){
return {
id: 1
}
},
mounted() {
this.getData()
},
methods: {
getData() {
axios.get('/api/notes/$id')
.then(res => {
console.log(res.data)
})
}
}
}
Answer the question
In order to leave comments, you need to log in
I solved it like this, but something tells me that there is a more elegant solution.
getData() {
this.url = this.url + this.id;
axios.get(this.url)
.then(res => {
console.log(res.data)
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question