Add An External Configuration File In Vue For Deployment?
I have to call an API (json-server) to retrieve data in order to populate my dropdowns within my Vue application. Instead of hard-coding within the app, I want to create an externa
Solution 1:
If you want the app build once and use same bundle on multiple servers with different configuration, this is right way to do it. ENV variables suggested in comments wont work as the values are "baked in" to the bundle...
However you are using fetch
in a wrong way. fetch
returns response which you are trying to call instead of calling response.json()
fetch(process.env.BASE_URL+ "config.json")
.then((response) => response.json())
.then((config) => {
Vue.prototype.$config = config
newVue({
router,
store,
render: (h) =>h(App)
}).$mount("#app")
})
Post a Comment for "Add An External Configuration File In Vue For Deployment?"