In my opinion i will go by creating a file called api.js and there exporting functions that call axios for the api calls. something like:
import axios from 'axios'
const API = axios.create({
baseURL: API_BASE_URL
})
export async function me () {
return await API.get('/me')
}
export async function usersList () {
return await API.get(`/users`)
}
export async function usersShow (id) {
return await API.get(`/users/${id}`)
}
export async function usersCreate (data) {
return await API.post('/users', data)
}
export async function usersUpdate (id, data) {
return await API.put(`/users/${id}`, data)
}
export async function usersDelete (id) {
return await API.delete(`/users/${id}`)
}
Then wherever you want to use it only import it:
...
<script>
import { usersList } as api from '@/api'
export default {
...
methods: {
logUsers () {
usersList().then(res => {
console.log(res)
})
}
}
...
}
</script>
...
So if sometime in the future I want to change axios for any other thing or add axios calls extra parameters like header and so on, all the api call I have it in one place.