gpt4 book ai didi

javascript - 为什么 window.location.href 在 Vue.js 中不起作用?

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

 <script>
logBox = new Vue({
el: "#logBox",
data: {
email : '',
password: ''
},
methods: {
handelSubmit: function(e) {
data = {};
data['email'] = this.email;
data['password'] = this.password;
$.ajax({
url: 'https://herokuapp.com/api/', //my url
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if(e.status != false){
alert("Login Success").then(function() {
// Redirect the user
window.location.href = "https://stackoverflow.com/";
console.log('The Ok Button was clicked.');
});
}
else {
alert("failed to login!");
}
}
});
return false;
}
},
});

这是我的登录代码。成功登录后,我需要重定向到成功页面,但 window.location.href 不起作用,我无法定向到新页面。那么,任何机构都可以解决我的问题吗?

最佳答案

alert()不是 promise 。您应该将其修复为:

          if (e.status != false) {
alert("Login Success");
// Redirect the user
window.location.href = "https://stackoverflow.com/";
}

关于javascript - 为什么 window.location.href 在 Vue.js 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46968973/

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