I have a Vue3 project(setted up using vue-cli and run as npm run serve
) which need a const
to be defined so that all services can use it. so my main.js
has this constant
// main.js
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'
import "jquery"
import "bootstrap-icons/font/bootstrap-icons.css";
let x = 'google'
export {x};
const app = createApp(App)
app.use(store)
app.use(router)
app.mount("#app")
my services/GetCategoriesService.js
is:
import { x } from "../main.js"
console.log(x)
and in my components/footer.vue
<script>
tag i execute the service script:
import * as $ from 'jquery'
import "../services/GetCategoriesService"
This will result in undefined but adding an extra console.log in my service will make hot reloading(I'm NOT refreshing the page)to run and now i can see two console.log with google
then I refresh the page and again see two console.log but with undefined
adding another console.log without refreshing result in three google prints, refresh Then I see three undefined
which is really weird. I'm using Firefox v 105.0
.
NOTE: Using named export of x
and console.log x
inside a function(which is called from footer.vue
) result in same behavior.