N
N
Nikolay Semenov2017-06-27 14:14:23
JavaScript
Nikolay Semenov, 2017-06-27 14:14:23

How to save current user data when leaving his page in Vue?

Guys and hello again.
There is a page with user data where he can edit them.
There are no buttons. the data needs to be saved before it leaves the page.
tried through

beforeRouteLeave(to, from, nextr) {
              debugger
              this.$store.dispatch('saveUserData', this.user);

              next();

          }

he passes it to action, here he comes (watched the debugger)
export const saveUserData = ({commit}, user) => {
    debugger
    commit(types.SAVE_USER_DATA), {
        user: user

    }
}

but in the mutation it seems to write user undefined
[types.SAVE_USER_DATA] (state, { user }) {
        debugger
         state.user = user
     }

Where is the mistake? tell

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-06-27
@nickola105

This post is weird:

commit(types.SAVE_USER_DATA), {
        user: user

    }

should be something like:
commit(types.SAVE_USER_DATA, {user: user})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question