Skip to content

Instantly share code, notes, and snippets.

@Sixl-Daniel
Last active October 4, 2020 09:10
Show Gist options
  • Save Sixl-Daniel/c191dbb42b4f01a60e94547ee57a1e66 to your computer and use it in GitHub Desktop.
Save Sixl-Daniel/c191dbb42b4f01a60e94547ee57a1e66 to your computer and use it in GitHub Desktop.
Vue.js environment variables
# 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
}
}
# 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