nuxtjs-examples
nuxtjs-examples copied to clipboard
ENV Throwing error on page / component.
Did you test your code before commit? its not working.. see the screenshot of error. However, I have fixed and commit on my Fork. (See Here)
Error Snapshot -

I found one easiest way to set configs (json) file and and use in any component.
Steps -
-
Create
setting.jsonfile in root directory. -
in middleware, create a file settings.js (or keep any name) and paste this code
import settings from '../settings.json'
export default function ({ store, route, redirect, req}) {
process.env = settings
}
3 in nuxt.config.js - add settings in
router: {
middleware: ['users', 'settings']
},
uses - In any component or page -
data(){
return {
settings: process.env
}
},
Now you can use settings anywhere in component.