A
A
Artur Galyaev2020-11-13 18:45:54
Vue.js
Artur Galyaev, 2020-11-13 18:45:54

How to force a Store refresh in Vuex?

After changing the state, I have to reset one state:

this.$store.commit('clients/SET_CURRENT_CLIENT', ID); // Изменить стейт
  this.$store.commit('budget/SET_SETTING', {setting: "dealerShipId", value: 0}); // Обнулить настройку

Then I catch the change and call the callback
this.$store.watch(
      (state) => {
        return state.budget.settings
      },
      () => {
        this.$store.dispatch('budget/GET')
      },
      {
        		deep:true
      	}
    )

The problem is that the state of the setting may already be 0 and the change will not be caught, how to force the update of the state?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-11-13
@art5455

deep:true

Well, since you are watching the object, replace it completely.
That is, instead obj[key] = valof doing obj = { ...obj, [key]: val }.

A
Aetae, 2020-11-13
@Aetae

The whole logic is built on reducing unnecessary useless calls. If you need to force update - force update by hand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question