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
81
votes
5 answers

VueJS access child component's data from parent

I'm using the vue-cli scaffold for webpack My Vue component structure/heirarchy currently looks like the following: App PDF Template Background Dynamic Template Image Static Template Image Markdown At the app level, I want a vuejs component…
Daniel Brown
  • 2,354
  • 3
  • 25
  • 39
77
votes
5 answers

Vuex: Call getters from action

Is there a way for a dispatch/action to call a getter inside of it? mutations: { setData(state, data) { state.data = data; } } actions: { sendDataToServer({ commit }, payload) { // call getter (data) and assign to…
The Bassman
  • 1,649
  • 2
  • 20
  • 27
75
votes
2 answers

How to access the getter from another vuex module?

Within a vuex getter I know it is possible to access the state from another vuex module like so: pages: (state, getters, rootState) => { console.log(rootState); } How can I access a getter from another vuex module instead of the state though?…
Stephan-v
  • 14,707
  • 17
  • 87
  • 176
69
votes
13 answers

How to clear state in vuex store?

My state in vuex store is huge. Is there a way to reset all the data in state in one go, instead of manually setting everything to null?
KaliCharan
  • 875
  • 1
  • 6
  • 12
67
votes
9 answers

Accessing Vuex state when defining Vue-Router routes

I have the following Vuex store (main.js): import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) //init store const store = new Vuex.Store({ state: { globalError: '', user: { authenticated: false } …
Ege Ersoz
  • 5,470
  • 5
  • 29
  • 46
60
votes
6 answers

Accessing getters within Vuex mutations

Within a Vuex store mutation, is it possible to access a getter? Consider the below example. new Vuex.Store({ state: { question: 'Is it possible to access getters within a Vuex mutation?' }, mutations: { …
ba0708
  • 8,528
  • 11
  • 61
  • 97
59
votes
6 answers

How to access Vuex module getters and mutations?

I'm trying to switch to using Vuex instead of my homegrown store object, and I must say I'm not finding the docs as clear as elsewhere in the Vue.js world. Let's say I have a Vuex module called 'products', with its own state, mutations, getters,…
John Moore
  • 5,167
  • 11
  • 40
  • 58
59
votes
4 answers

vuexjs getter with argument

Is there a way to pass parameter into getter of vuex store? Something like: new Vuex.Store({ getters: { someMethod(arg){ // return data from store with query on args } } }) So that in component I could use