You can fetch config.json
from public folder and then load your Vue app in the resolve callback
Place your configuration keys in /public/config.json
file
{
"KEY": "value"
}
Then in your /src/main.js
file
fetch(process.env.BASE_URL + "config.json")
.then((response) => response.json())
.then((config) => {
Vue.prototype.$config = config
new Vue({
router,
store,
render: (h) => h(App)
}).$mount("#app")
})
You will have your configuration loaded application-wide. You can then just use
mounted() {
this.$config.KEY // "value"
}
in your Vue components
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…