Last active
October 4, 2020 09:10
-
-
Save Sixl-Daniel/c191dbb42b4f01a60e94547ee57a1e66 to your computer and use it in GitHub Desktop.
Vue.js environment variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config.js | |
const config = { | |
..., | |
features: { | |
... | |
}. | |
... | |
} | |
function feature (name) { | |
return config.features[name] | |
} | |
function parse (value, fallback) { | |
if (typeof value === 'undefined') { | |
return fallback | |
} | |
switch (typeof fallback) { | |
case 'boolean' : | |
return !!JSON.parse(value) | |
case 'number' : | |
return JSON.parse(value) | |
default : | |
return value | |
} | |
} | |
export { | |
config | |
} | |
export default { | |
install (Vue) { | |
Vue.appConfig = config | |
Vue.feature = feature | |
Vue.prototype.$appConfig = config | |
Vue.prototype.$feature = feature | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main.js | |
import Vue from 'vue` | |
import configPlugin from '@/config' | |
Vue.use(configPlugin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment