繁体   English   中英

在 Vue 中,如何使用 window.history.go(-1) 使浏览器到 go 返回上一页

[英]In Vue, how to make browser to go back to previous page using window.history.go(-1)

嗨,我正在制作一个基于Vue的网页,但我现在遇到了麻烦。 我最初使用router.go(-1)来阻止通过地址访问(例如: ../client/mypage ->../admin/mypage )并重定向到上一页,但它不起作用,因为页面本身已刷新。 (在我看来,路由器历史堆栈是空的)

所以,我发现的是window.history.go(-1) ,但即使它的长度大于 1,它也不起作用。

有什么问题,我应该如何解决?

    mounted(){
        if (this.auth) { // when you access through address, check the authority  
            this.$router.go(-1); //doesn't work
            window.history.go(-1); //doesn't work either
        }
    }

图片:console.log(window.history)

试试这个。

mounted(){
        if (!this.auth) {  //If not authenticated
            window.history.back();
        }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM