0

我正在用 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";
            }
        }
    },

}
4

0 回答 0