B
B
Bogdan2018-03-15 10:59:32
Vue.js
Bogdan, 2018-03-15 10:59:32

Storing global variables?

Hello. Please tell me the best way to store global variables:
1) window.baseUrl
2) in Vuex -> state -> baseUrl
3) Vue.prototype.$baseUrl= '...'
or is there another solution? Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Kitmanov, 2018-03-15
@bogdan_uman

It only makes sense to store in vuex if this value changes (based on the name, this is unlikely).
Vue.prototype.$baseUrland window.baseUrlnot the most elegant solution, because not all components need this constant.
I would create some config.js and in it and where you need to read -- In my opinion, if you do not use any DI , this is the cleanest solution.

N
Nikita Velko, 2018-03-15
@nikichv

If we are talking specifically about storing baseURL to access the API, then use environment variables - this is the most correct option. Using this approach, you can easily redefine this variable when starting the project in different environments (dev, production) without changing the application code itself.
For example, an article.
Simply put, in your code you write something like:
And start the NodeJS server with the following command: PS The most common package for working with env re... NodeJS documentation

V
Vladislav Nagorny, 2018-03-15
@esvils

You can read it off. dock , also read about VUEX

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question