A
A
Artur Galyaev2020-11-13 12:37:34
Vue.js
Artur Galyaev, 2020-11-13 12:37:34

How to call action after state change?

I make a date picker on Vue, after changes in the date picker, the state changes:

computed: {
    month: {
      get () {
        return this.$store.budget.state.settings.month
      },
      set (value) {
        this.$store.commit('budget/SET_SETTING', {setting: 'month', value})
      }
    }
  },

Here is the store:
state: {
        settings: {
        	month: moment().month(),
      quarter: 1,
      viewType: "daysOfMonth",
      year: moment().year(),
        },
    },
    mutations: {
        SET_SETTING(state, {setting, value}) {
        	state.settings[setting] = value
        }
    },
    actions: {
        GET ({ commit, state }) {
            let {year, month} = state.settings
            // ЗАПРОС
        },

I need to call action GET after changes in date settings. How to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-11-13
@art5455

If this change should always be made, regardless of anything else, then simply: watch :

store.watch(state => state.budget.settings.month, () => store.dispatch('budget/GET'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question