0
votes

Hello im trying to add {{this.$route.params}} to my axios url for get the data on dedicated profil pages. here is the part i want to add in axios url the "id" : enter image description here

The Axios code from 'RikLamers' who explain me how to get data, it is where i want to add "this.$route.params" :

 data() {
  return {
    results: [],
  }
},
 async  mounted() {
  await axios.get(`API url" ${to.params.id}`)
.then(response => {this.results = response.data.content})

 }, 

but i mistake somewhere, hope someone can explain me ?

1
Do you want to fetch the data based on route params?Naren
Yes it is that :) i need to add "id" like aurelie-wulff-2 to my axios get urlJ.O
Cool, Below answer will work!Naren

1 Answers

1
votes

You can access URL param using this.$route.params.id. Use try catch, when you use await.

data() {
  return {
    results: [],
  }
},
async  mounted() {
  try {
    const response = await axios.get(`[Your API URL]/${this.$route.params.id}`)
    this.results = response.data.content
  catch (e) {}
},