How do I declare a global variable in a project generated by vue-cli?

how do I declare a global variable in a project generated by vue-cli? My personal understanding is that main.js is an entry file and App.vue is a root-level component. If a variable is declared here, webpack will be packaged recursively. But why can"t this variable be referenced in other .vue script?


declare your variables in main.js , then Vue.prototype.xx = xx;
other vue files this.xx can be accessed,
you can also write them into a js file, and then import xx from "xx" in main.js , Vue.prototype.xx = xx; `


landlord, hello! This is fine. You can define a global variable in main.js, such as window.userName = 'hello' . It is OK to use window.userName directly on other pages. A personal test is fine.


global variable? vuex?


try writing in index.html, either you write in data on the page or you write in store

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b322fa-2bdfe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b322fa-2bdfe.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?