javascript - 在 Vue 中,如何使用 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
}
}
解决方案
试试这个。
mounted(){
if (!this.auth) { //If not authenticated
window.history.back();
}
}
推荐阅读
- perforce - 如何在当前 CL 中从父级到子级进行 p4 合并?
- html - 在材料手风琴中重新加载数据源后保持展开的行状态
- selenium - 测试如何在某些错误跟踪工具上获取 post 问题的 aftermethod 中的所有日志步骤
- python - 斐波那契尾递归背后的直觉
- javascript - 如何取消链接grapejs链接
- python - 拆分为字节,布尔对可变
- cassandra - Cassandra:CompactionExecutor,达到最大内存使用量
- python-3.x - 经理不可用;'auth.User' 已替换为 'accounts.CustomUser'
- python - 错误:找不到模块“libmultinest.dll”
- javascript - 在执行 $aggrigate $lookup 之后,如何将某些字段的过滤器添加为可选?需要进行哪些更改?