I am in the process of developing a versatile API service using axios.
api.js
import axios from 'axios'
export default () => {
return axios.create({
baseURL: `${window.location.origin}/`
})
}
authenticationService.js
import api from '@/services/api.js'
export default {
login(credentials) {
return api.post('...', credentials)
}
}
vuex action
import authenticationService from '@/services/authentication/authenticationService'
async login({commit}, credentials) {
try {
let response = await authenticationService.login(credentials)
console.log(response)
} catch(er) {
console.log(er)
}
})
Error Encountered*
_services_api__WEBPACK_IMPORTED_MODULE_0__.post is not a function
at Object.login (authenticationService.js:6)
Upon further examination:
login: function login(credentials) {
return _services_api__WEBPACK_IMPORTED_MODULE_0__["post"]('...', credentials);
}
It seems like there may be an issue with importing the api function correctly which initializes axios?