Vue: what is the best way to share globals vars?

Created on 8 Dec 2014  Â·  2Comments  Â·  Source: vuejs/vue

I am willing to drop a current angular app, and I am wondering how to use vue in the context where I want to share global infos (like user name, counters, etc)

  • shall I reproduce the same layout as with Angular, where I got the main app linked to body

    --> Will it have impact on performance if I do that with Vue? shall I avoid this?
  • or is it faster/safer/better to simply use a global app variable (attached to window or not)

Every view object should be able to access the data as if it was part of its model. I know
there exists subviews, my question is: what is recommended considering perf or maintainability?

I put this as an issue linked to the documentation, in a chapter like "managing larger apps".

thanks

Most helpful comment

The recommended approach is: do not share global vars. Pass them down from the root component.
Your root vm can be linked to <body>, there should be no problem (if Angular can handle it then Vue definitely can too).

All 2 comments

The recommended approach is: do not share global vars. Pass them down from the root component.
Your root vm can be linked to <body>, there should be no problem (if Angular can handle it then Vue definitely can too).

Great.
Thanks for the answer.

Was this page helpful?
0 / 5 - 0 ratings