Questions tagged [vuex]

Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion.

Vuex is a data management library by the creator of Vue.js. It is designed to help build larger applications in a more maintainable way by following principles similar to those made popular by Facebook’s Flux library (and subsequent iterations by community like redux).

Principles

  • Terse
  • Testable
  • Reactive
  • Single State Tree
  • Hot Reloading
  • Time Travel (with vue-devtools support)

GitHub: https://github.com/vuejs/vuex Documentation: https://vuex.vuejs.org/en/

6459 questions
223
votes
19 answers

vue.js 2 how to watch store values from vuex

I am using vuex and vuejs 2 together. I am new to vuex, I want to watch a store variable change. I want to add the watch function in my vue component This is what I have so far: import Vue from 'vue'; import { MY_STATE, } from…
raffffffff
  • 2,567
  • 4
  • 14
  • 14
214
votes
13 answers

Vuex Action vs Mutations

In Vuex, what is the logic of having both "actions" and "mutations?" I understand the logic of components not being able to modify state (which seems smart), but having both actions and mutations seems like you are writing one function to trigger…
Kobi
  • 2,839
  • 3
  • 13
  • 17
196
votes
1 answer

Is there a way to dispatch actions between two namespaced vuex modules?

Is it possible to dispatch an action between namespaced modules? E.g. I have vuex modules "gameboard" and "notification". Each are namespaced. I would like to dispatch an action from the gameboard to the notification module. I thought I could use…
Chris Schmitz
  • 16,386
  • 23
  • 70
  • 118
174
votes
5 answers

Call an action from within another action

I have the following setup for my actions: get1: ({commit}) => { //things this.get2(); //this is my question! }, get2: ({commit}) => { //things }, I want to be able to call one action from within another, so in this example I want to be able…
muttley91
  • 11,995
  • 27
  • 97
  • 144
168
votes
3 answers

Vuex - passing multiple parameters to mutation

I am trying to authenticate a user using vuejs and laravel's passport.I am not able to figure out how to send multiple parameters to the vuex mutation via an action. - store - export default new Vuex.Store({ state: { isAuth:…
Schwesi
  • 3,760
  • 8
  • 28
  • 54
146
votes
5 answers

Returning Promises from Vuex actions

I recently started migrating things from jQ to a more structured framework being VueJS, and I love it! Conceptually, Vuex has been a bit of a paradigm shift for me, but I'm confident I know what its all about now, and totally get it! But there exist…
Daniel Park
  • 3,433
  • 3
  • 21
  • 34
144
votes
4 answers

Vuex - Computed property "name" was assigned to but it has no setter

I have a component with some form validation. It is a multi step checkout form. The code below is for the first step. I'd like to validate that the user entered some text, store their name in the global state and then send then to the next step. I…
Connor Leech
  • 15,156
  • 27
  • 91
  • 133
135
votes
8 answers

Communication between sibling components in Vue.js 2.0

Overview In Vue.js 2.x, model.sync will be deprecated. So, what is a proper way to communicate between sibling components in Vue.js 2.x? Background As I understand Vue.js 2.x, the preferred method for sibling communication is to use a store or an…
Sergei Panfilov
  • 12,838
  • 13
  • 66
  • 89
133
votes
5 answers

How do I call a getter from another getter in Vuex?

Consider a simple Vue blog: I'm using Vuex as my datastore and I need to set up two getters: a getPost getter for retrieving a post by ID, as well as a listFeaturedPosts that returns the first few characters of each featured post. The datastore…
User not found
  • 1,649
  • 2
  • 12
  • 19
128
votes
6 answers

Vuex state on page refresh

My app uses the Firebase API for User Authentication, saving the Login status as a boolean value in a Vuex State. When the user logs in I set the login status and conditionally display the Login/Logout button accordingly. But when the​ page is…
boomboxboy
  • 1,884
  • 5
  • 16
  • 29
113
votes
6 answers

Vuex: Access State From Another Module

I want to access state.session in instance.js from records_view.js. How is this accomplished? store/modules/instance.js const state = { // This is what I want to access in records_view.js session: {} }; const getters = { sessionGetter: state…
Donnie
  • 5,209
  • 7
  • 29
  • 49
89
votes
9 answers

How do I format currencies in a Vue component?

My Vue component is like this :