gpt4 book ai didi

vuejs2 - 未被捕获(处于 promise 状态)NavigationDuplicated错误出现在无效凭据上

转载 作者:行者123 更新时间:2023-12-03 16:12:32 24 4
gpt4 key购买 nike

在我的Laravel 5.8/“vue”:“^ 2.6.10”/“vuex”:“^ 3.1.0” app在resources/js/components/Login.vue文件中,我有方法

methods: {
authenticate() {
this.$store.dispatch('login'); // calling action

login(this.$data.form)
.then((res) => {

this.$store.commit("setLoginSuccess", res); // calling mutation
this.$store.dispatch('retrieveHostelBookmarks', res.user.id);
this.$store.dispatch('retrievePersonalOptions', res.user.id);


this.$router.push({path: '/personal'}); // For debugging!
})
.catch((error) => {
console.log("=== error::")
console.log(error)
this.$store.commit("setLoginFailed", {error}); // calling mutation
});
}

在resources/js/helpers/authFuncs.js中,我有以下定义:
export function login(credentials) {
return new Promise((res, rej) => {
axios.post('/api/auth/login', credentials)
.then((response) => {
setAuthorizationToken(response.data.access_token);
res(response.data);
})
.catch((err) =>{
console.error(err)
rej("Wrong email or password");
})
})
}

问题是在控制台中的无效凭据上,我在输出末尾看到promise警告:
VM836:1 POST http://127.0.0.1:8084/api/auth/login 401 (Unauthorized)
(anonymous) @ VM836:1
dispatchXhrRequest @ app.js?dt=1571914585:311
xhrAdapter @ app.js?dt=1571914585:150
dispatchRequest @ app.js?dt=1571914585:758
Promise.then (async)
request @ app.js?dt=1571914585:560
Axios.<computed> @ app.js?dt=1571914585:585
...
app.js?dt=1571914585:10042 === error::
app.js?dt=1571914585:10043 Wrong email or password
app.js?dt=1571914585:131483 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/login") is not allowed", stack: "Error↵ at new NavigationDuplicated (http://127.…/127.0.0.1:8084/js/app.js?dt=1571914585:148080:12"}

为什么显示此警告以及如何解决?

最佳答案

我们可以使用this.$router.push(route, () => {});摆脱错误。

关于vuejs2 - 未被捕获(处于 promise 状态)NavigationDuplicated错误出现在无效凭据上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58540009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com