Having some trouble with Vue and Axios - encountering the following error message:
[Vue warn]: Error in created hook: "TypeError: can't access property "get", vue__WEBPACK_IMPORTED_MODULE_0__.default.axios is undefined"
Here's the code snippet:
Api.service.js
import Vue from "vue";
import axios from "axios";
import VueAxios from "vue-axios";
import JwtService from "./jwt.service";
const ApiService = {
init() {
Vue.use(VueAxios, axios);
axios.defaults.baseURL = "http://hyper.test/api";
},
}
BannerDataService.js:
import ApiService from "../api.service";
class BannerDataService {
constructor() {
}
all() {
return ApiService.get('site/banners')
}
get(id) {
return ApiService.get(`site/banners/${id}`)
}
}
export default new BannerDataService();
Index.vue:
getBanners() {
BannerDataService.all().then(response => {
console.debug(response)
}).catch(err => {
console.debug(err)
})
}
Error message in console:
[Vue warn]: Error in created hook: "TypeError: can't access property "get", vue__WEBPACK_IMPORTED_MODULE_0__.default.axios is undefined"