[Vuejs]-How to call different api links within same page?

0👍

Simply move your axios call to it’s own method:

methods: {
  getTeams(id, page) {
    return axios({
      id,
      "method":"GET",
      "url": `https://api-football-v1.p.rapidapi.com/v2/teams/league/${page}`,
      "headers":{
        "content-type":"application/octet-stream",
        "x-rapidapi-host":"api-football-v1.p.rapidapi.com",
        "x-rapidapi-key":"d67f727cf5msh4507fcb80b215bbp12e824jsn13d8d45c4d68",
        "useQueryString":true
      }
    })
  }
}

You can then call it from somewhere else with

this.getTeams(39, 2).then(response => {
  this.dataList = response.data.api.teams
});
// No catch, since we want to have the actual stack trace and do not handle the error in any way

Leave a comment