Friday, February 22, 2019

How To setup global settings and use in methods or vue file in NUXTJS

Let say you want to setup a json file were all static settings are saved. you want to use dierctly either in codes or in view pages across the application.

Here is the steps.

1.  Create a file setting.json in root directory (where your project exists)
        your settings will be like this -

2.  Create another file "settings.js" in middleware folder
3.  paste this code inside setting.js file

4. open your nuxt.config.js and find router-middleware. if not then paste this code

That's it.

Now See how to use

in code (E.g in create or inside method)

created(){
  var a =  $s.key
}

and in .vue page

{{ $s.key}} or {{ $s['key']}}