Using env variables inside Vue
See original GitHub issueHi, and excellent work!
I’ve tried creating a “.env” file, and editing Webpack to include additional environmental variables, but both methods fail for similar reasons.
So while environmental variables in the “.env” file pass npm run watch
I get errors in Chrome if I attempt to use them:
mounted () {
console.log("Index", VUE_APP_VAR)
}
ReferenceError: VUE_APP_VAR is not defined
If I use them inside Webpack, it renders the variables, but then fails to recognise them as such (I was using them in Axios).
What would the correct method be?
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Modes and Environment Variables - Vue CLI
When running vue-cli-service , environment variables are loaded from all corresponding files. If they don't contain a NODE_ENV variable, it will ...
Read more >Using Environment Variables with Vue.js - Stack Overflow
Create two files in root folder (near by package.json) .env and . · Add variables to theese files with prefix VUE_APP_ eg: ...
Read more >How to Use Environment Variables in Vue.js - Medium
The environment variables can be accessed anywhere in your Vue application through the global process.env object. Here I have added two ...
Read more >How to Use .env Environment Variables in Vue | HackerNoon
Vue can only use variables that start with 'VUE_APP_' and 'Vue_API_KEY' Vue-CLS lets us use these variables when we run our applications. Using...
Read more >How To Use Environment Variables in Vue.js - DigitalOcean
With Vue.js, it is possible to use environment variables through files with the .env file extension. These files are responsible for storing ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had to use:
Without the
path
it wouldn’t work.Thanks for the assistance — much appreciated!
That’s what I assumed. Yes, weird.