Trying my hand at creating an API service with this syntax:
apiservice.js
import axios from 'axios'
import * as users from '@/plugins/apiservice/modules/users';
const apiservice = axios.create({
baseURL: process.env.VUE_APP_URL,
withCredentials: false,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${localStorage.getItem('sessionToken')}`
},
})
export default {apiservice, users};
users.js
import apiservice from "@/plugins/apiservice";
const login = async (params) => {
try {
const result = await apiservice.post('/login', params);
return result.data;
} catch (error) {
return error;
}
}
export {login};
Component.vue
import apiservice from '@/plugins/apiservice';
const response = await apiservice.users.login(this.loginData);
Encountered an error when trying to enter data TypeError: plugins_apiservice__WEBPACK_IMPORTED_MODULE_2_.default.post is not a function
NOTE 1: A GET request was successful with a 200 response
NOTE 2: Using the exact login function within apiservice works perfectly