Vue.js 为什么尽管调用了catch,我的VueJS登录仍在重新加载?
我有以下代码。正在调用catch(),我可以看到toastr警报。但是,在页面重新加载后,会立即执行此操作。知道为什么吗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
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登录操作代码吗。