vue路由器未使用同一对象的新数据更新url

时间:2018-12-18 16:20:57

标签: javascript vuejs2 vue-router vuetify.js

我有一个vue登录表单,该表单返回错误作为查询。在第一个错误后,查询对象将加载错误字符串,即使随后的错误出现在控制台中,后续错误也不会出现...

store.js ...

userLogin({ commit }, { email, password }) {
      firebase
        .auth()
        .signInWithEmailAndPassword(email, password)
        .then(user => {
          commit("setUser", user);
          commit("setIsAuthenticated", true);
          console.log("User: " + user.user.uid + "found")
          router.push("/dashboard");
        })
        .catch((error) => {
          commit("setUser", null);
          commit("setIsAuthenticated", false);
          console.log("Login Error: " + error.message);
          router.go({name: "signin", force: true,  query: {errorMessage: error.message, signinError: true}});
        });
    },

登录脚本。...

    data() {
        return {
          email: "",
          password: "",
          performingRequest: false,
          signinError: false,
          signupSuccessful: false,
          errorMessage: "",
          successMessage: ""
        };
      },
      created() {
        if(this.$route.query.signinError) {
          this.signinError = this.$route.query.signinError;
          this.errorMessage = this.$route.query.errorMessage;
        }
      },
methods: {
    validateStep(scope) {
      this.$validator.validateAll(scope).then(result => {
        if (result) {
          this.performingRequest = true
          this.$store.dispatch("userLogin", {
            email: this.email,
            password: this.password
          })
        }
      });
    }
  }

登录模板。...

<v-alert :value="signinError" type="error" >
          {{errorMessage}}
          </v-alert>
          <v-alert :value="signupSuccessful" type="success" >
          {{successMessage}}
          </v-alert>

1 个答案:

答案 0 :(得分:0)

我不确定我是否完全理解您的问题...但是乍一看,我发现了一个问题: 这个:router.go();现在是:router.push(); 检查此文档:https://router.vuejs.org/guide/essentials/navigation.html

让我知道是否需要进一步的帮助。