I created an empty vue3 project. And I created global.js to the public file.
global.js;
window.testPrint = "test message";
export default {}
vue.config.js;
// vue.config.js
/**
* @type {import('@vue/cli-service').ProjectOptions}
*/
module.exports = {
publicPath: "./"
};
App.vue;
<template>
<p>
{{getTest()}}
</p>
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view />
</template>
<script>
export default {
methods: {
getTest() {
return window.testPrint;
}
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
}
#nav a {
font-weight: bold;
color: #2c3e50;
}
#nav a.router-link-exact-active {
color: #42b983;
}
</style>
main.js;
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
createApp(App).use(store).use(router).mount("#app");
import "../public/global.js";
On the screen output that I have built and run on iis, window.testPrint = "test message"; shaped. When I change this value in global.js and do Ctrl+F5, the screen does not change and still remains as "test message".