My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Is Vuex (Flux) solely for SPA?

Emil Moe's photo
Emil Moe
·Oct 15, 2016

Does Vuex (VueJS version of Flux) only has a purpose when you are building Single Page Applications (SPA)?

I'm trying to think of an architecture for my future applications and one thing that I have been lacking is when multiple components needs to talk to each other. For example I have a widget that sums up a list. The widget and the list are 2 different components since the list is used in another place too without the widget. I have had troubles updating the widget when an item from the list is updated or removed. My initial solution was to update the widget with events - which quickly becomes messy as it's hard to keep an overview of events and such, also events are removed from Vue2.

My next thought was that maybe Vuex could be used instead, but it looks more like that is for SPAs?

And finally I am now considering creating less generic components and more page specific components and call them controllers. I don't know if that breaks the logic behind Vue. I would sort them in 2 different folders:

  • js/components
  • js/controllers

I would also name the components just whatever fits as now, but name the controllers with a suffix like ProfileController, although basically it's all components.

The idea is that the controller component would be able to handle cross component values and that I don't have to overflow the VM. It's sort of AngularJS' controllers.

I would still use the VM to handle global variables such as the current users attributes and API urls. Maybe Vuex would be handy here? I guess I could call this.$store.user.id. Btw can Vuex contain methods?

I am not building SPA, but my applications are heavily based on JavaScript page-wise.