I am writing a project which uses so many Axios calls from different pages. Instead of using Axios calls multiple times, is it possible to write a single Axios call function and use it in each pages.
For ex, define an "axiosCall" function once and than use it in different pages by just calling that function.
axiosCall (serviceName, parameter) {
axios
.get(`http://localhost/xApi/` + serviceName + `/` + parameter)
.then(response => {
return response.data
})
.catch(e => {
this.exceptionHandler('Error at get ' + serviceName + ' : ', e)
})
}
Then use it like
var userData = axiosCall('user',1)
var roleData = axiosCall('role',2)
Thanks in advance