My main.js
file is responsible for creating an app
and adding components like router
, store
, and axios
.
Here is how I'm globally adding axios
:
import {createSSRApp, createApp, h} from 'vue';
import axios from 'axios'
const rootComponent = {
render: () => h(App),
components: { App }
}
const app = createApp(rootComponent);
app.config.globalProperties.$axios=axios;
if (process.env.NODE_ENV === 'development') {
app.$axios.defaults.baseURL = 'http://localhost:8080'; // This triggers an error
}
However, when I try to run this in the browser using webpack-dev-server
, I encounter the following error:
Uncaught TypeError: app.$axios is undefined
I'm confused as to why app.$axios
is showing as undefined. Can anyone help explain this?