我正在用laravel和vuejs编写POS系统。登录我正在使用JWT-auth。现在,如果已有“现金会话”,系统需要重定向到vue-route /Dashboard
,否则您需要重定向到/Cash
。现在我尝试了各种各样的东西,但没有任何作用。它始终重定向到/Cash
。
有没有人有解决方案?
methods: {
login() {
let app = this;
this.$auth.login({
params: {
username: app.username,
password: app.password
},
success: function () {
},
error: function (resp) {
alert('Error: ' + resp.response.data.msg)
},
redirect: app.redirectURL(),
fetchUser: true
});
},
setText(gebruiker) {
this.buttonText = gebruiker;
this.username = gebruiker;
},
redirectURL () {
let cashActive = false;
axios.get('cash/active').then(response => {
console.log(response.data.active);
cashActive = response.data.active;
});
console.log("Cash Active: " + cashActive);
if (!cashActive) {
console.log("Return /Cash");
return "Cash";
} else {
console.log("Return /dashboard");
return "/Dashboard";
}
}
}
编辑:我尝试过异步功能,但重定向仍然不起作用。我的页面没有重定向。我在函数redirectURL中返回的内容一定存在问题。有人可以帮忙吗?
methods: {
login() {
let app = this;
this.$auth.login({
params: {
username: app.username,
password: app.password
},
success: function () {
},
error: function (resp) {
alert('Error: ' + resp.response.data.msg)
},
redirect: app.redirectURL(),
fetchUser: true
});
},
setText(gebruiker) {
this.buttonText = gebruiker;
this.username = gebruiker;
},
async redirectURL () {
let cashActive = await axios.get('cash/active').then(response => {
//console.log(response.data.active);
return response.data.active;
});
console.log("Cash Active: " + cashActive);
if (!cashActive) {
console.log("Return /cash");
return "/cash";
} else {
console.log("Return /dashboard");
return "/dashboard";
}
}
},
}