0

Given a Nuxt project, how to get values from inside nuxt.config.js, globally?

For example...

nuxt.config.js

    myObject: {
        myString: 'hello!'
    },

myVueComponent.vue

Looking for a convenient way to get Nuxt config properties...

...in component template: {{ <a-way-to-access-Nuxt-config>.myObject.myString }}

or in script: this.<a-way-to-access-Nuxt-config>.myObject.myString

Kalnode
  • 9,386
  • 3
  • 34
  • 62
  • What about a vuex store or env variables? Otherwise, just make it a global variable on the `window`. – kissu Nov 14 '22 at 13:41
  • Here is an example for env variables: https://stackoverflow.com/a/67705541/8816585 Here for vuex: https://nuxtjs.org/docs/directory-structure/store#store-directory – kissu Nov 14 '22 at 13:44
  • You should just use the store to achieve what you want. – brance Nov 14 '22 at 13:45
  • I use env and VueX all over the place; well aware of these things. I just don't want to add an action/mutator/getter just for one simple variable that is never set dynamically. I'll move to Pina in the future (no longer use VueX); but that's besides the case. – Kalnode Nov 14 '22 at 13:47
  • "Otherwise, just make it a global variable on the window." if you want something dirty. Having an exported variable from an `/utils/constants.js` directory is also fine that you could import where needed. – kissu Nov 14 '22 at 13:48
  • This answer is relevant: https://stackoverflow.com/a/59415226/4378314 – Kalnode Nov 14 '22 at 13:58
  • Nothing more than what I've shared above already. And you told us that you know how to use env variables already. – kissu Nov 14 '22 at 13:59
  • Yes, I just posted the link for future people; I will use the env way. – Kalnode Nov 14 '22 at 14:01
  • So, do you need anything else here? – kissu Nov 14 '22 at 14:42

0 Answers0