nuxtjs-examples icon indicating copy to clipboard operation
nuxtjs-examples copied to clipboard

ENV Throwing error on page / component.

Open sudhir600 opened this issue 6 years ago • 1 comments

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 - image

sudhir600 avatar Feb 06 '19 06:02 sudhir600

I found one easiest way to set configs (json) file and and use in any component.

Steps -

  1. Create setting.json file in root directory.

  2. 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.

sudhir600 avatar Feb 06 '19 09:02 sudhir600