D
D
danilr2019-03-07 14:01:51
JavaScript
danilr, 2019-03-07 14:01:51

How to execute actions in method on successful/failed request from actions vuex?

The bottom line is that I have a request in vuex, when the server responds, I need to call izitoaster (popup with info everything is ok or not), as I was told from vuex itself, it cannot be called, so I need to somehow call izitoast from the component method using a promise where the action is called. Tell me how to do it?
here in vuex:

setEditNewGroup(context, formGroupData) {
      HTTP.post(Routes.saveGroupNewEdit, formGroupData)
        .then(({ data }) => {
          console.log(formGroupData)
          // if (!formGroupData.id){
            context.commit('getNewAddGroup', {
              data: data,
              formGroupData: formGroupData
            })
          // }
        })
        .catch(error => {
          // this.$toast.error('Ошибка загрузки данных. Попробуйте ещё раз')
          console.error(error);
        })
    }

Here is the code in the component:
handleSaveGroup(){

      this.$store.dispatch('administration/setEditNewGroup', this.formGroupData)
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-07
@danilr

Let's read the documentation more carefully :

The first thing to know is that it store.dispatchcan handle a Promise returned by an action handler and it also returns a Promise.

You return a promise from your action - then - you call what you need there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question