Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 为什么尽管调用了catch,我的VueJS登录仍在重新加载?_Vue.js - Fatal编程技术网

Vue.js 为什么尽管调用了catch,我的VueJS登录仍在重新加载?

Vue.js 为什么尽管调用了catch,我的VueJS登录仍在重新加载?,vue.js,Vue.js,我有以下代码。正在调用catch(),我可以看到toastr警报。但是,在页面重新加载后,会立即执行此操作。知道为什么吗 signIn() { this.$store .dispatch('auth/login', this.credentials) .then(() => { this.$toastr.s('You are successfully logged in') this.$router.push({ na

我有以下代码。正在调用catch(),我可以看到toastr警报。但是,在页面重新加载后,会立即执行此操作。知道为什么吗

signIn() {
    this.$store
    .dispatch('auth/login', this.credentials)
    .then(() => {
            this.$toastr.s('You are successfully logged in')
            this.$router.push({ name: 'About' })

    })
    .catch(() => {
        // this.$toastr.e('You are successfully logged in')
      this.$toastr.e('Please check the form')

    })
}
登录代码:

login({ commit }, data) {
    commit(types.AUTH_ERROR_CHANGE, null)
    // console.log(process.env.VUE_APP_API_URL);
    const url = process.env.VUE_APP_API_URL + '/authentication_token'

    return new Promise((resolve, reject) => {
        axios
      .post(url, data)
      .then(response => {
        commit(types.AUTH_UPDATE_TOKEN, response.data)
        resolve(state)
      })
      .catch(() => {
        commit(types.AUTH_ERROR_CHANGE, 'Incorrect username or password')
        reject(state)
      })
    })
  },``

对不起,问题完全出在别处了

我在以前的代码中使用了axios拦截器:

axios.interceptors.response.use(
  data => {
    store.commit('general/' + types.LOADING_STOP)

    return data
  },
  error => {
    store.commit('general/' + types.LOADING_STOP)

    if (
      error.response &&
      error.response.status &&
      error.response.status === 401
    ) {
     // window.location.href = '/login'
    }

    return Promise.reject(error)
  }

我有一个旧位置。href在那里

你能分享你的vuex登录操作代码吗。