Creé un proyecto vue3 vacío. Y creé global.js en el archivo público.
global.js;
window.testPrint = "test message"; export default {}vue.config.js;
// vue.config.js /** * @type {import('@vue/cli-service').ProjectOptions} */ module.exports = { publicPath: "./" };Aplicación.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>principal.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";En la salida de pantalla que construí y ejecuté en iis, window.testPrint = "mensaje de prueba"; conformado. Cuando cambio este valor en global.js y hago Ctrl+F5, la pantalla no cambia y aún permanece como "mensaje de prueba".