Skip to content

Vue Navigator firing even the Vuex Dispatch response is pending. #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JacobFJ opened this issue Jan 12, 2021 · 0 comments
Closed

Vue Navigator firing even the Vuex Dispatch response is pending. #70

JacobFJ opened this issue Jan 12, 2021 · 0 comments

Comments

@JacobFJ
Copy link

JacobFJ commented Jan 12, 2021

Hello,

I just use this very efficient way of navigation library
but I encounter a problem between vuex and this navigation library

Expected to happen:
Wait for API response before firing this.$navigator.navigate('thispath')

Current:
Once @tap="handleLogin" vuex dispatch will run but vue navigator will fire even the response is pending in dev console

Reproduce:

Login.vue

    handleLogin() {
      if (this.user.mobile && this.user.password) {
        this.$store.dispatch("connect/login", this.user).then(
          () => {
           // running even the response is pending.
            this.$navigator.navigate("/auth/");
           //Testing alert
            alert();
          },
          (error) => {
            alert("Not found");
          }
        );

AuthService.js

  login(user) {
    return axios
      .post(API_URL + 'login', {
        mobile: user.mobile,
        password: user.password
      })
      .then(response => {
        if (response.data) {
          // mock
        }

        return response.data;
      });
  }

Vuex Module

   login({ commit }, user) {
      return AuthService.login(user).then(
        user => {
          commit('loginSuccess', user);
          return Promise.resolve(user);
        },
        error => {
          commit('loginFailure');
          return Promise.reject(error);
        }
      );

Visual Ref:

DevConsole API Request

CLI Output

Thanks

@JacobFJ JacobFJ closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant