@click=“this.$router.go(-1)”
时间: 2024-06-04 16:10:37 浏览: 42
This is a Vue.js directive used to navigate back to the previous page in the browser history using the Vue Router. The `click` attribute specifies that the directive should trigger when the element is clicked, and the value `"this.$router.go(-1)"` is the JavaScript code that tells the router to go back one step in the history. This directive can be used on any HTML element that can be clicked, such as a button or a link.
相关问题
this.$router.go的实现原理
this.$router.go的实现原理是通过改变浏览器的历史记录来实现路由跳转。当调用this.$router.go(n)时,n表示要向前或向后跳转的步数。如果n为正数,则向前跳转n步;如果n为负数,则向后跳转n步。具体实现原理如下:
1. 当调用this.$router.go(n)时,Vue Router会检查当前路由的历史记录长度。
2. 如果n大于0并且小于或等于历史记录长度,则通过window.history.go(n)来执行向前跳转n步。
3. 如果n小于0并且的绝对值小于或等于历史记录长度,则通过window.history.go(n)来执行向后跳转n步。
4. 如果n超过历史记录长度,则通过window.location.reload()来刷新页面,达到跳转到指定页面的效果。
总之,this.$router.go的实现原理是通过改变浏览器的历史记录来实现路由跳转。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [vue this.$router.push 页面不刷新总结(8种解决方式----覆盖所有场景)](https://blog.csdn.net/qq_38143787/article/details/120920610)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [vue 刷新当前页面,使用this.$router.go(0)闪白问题(使用provide / inject)](https://blog.csdn.net/a460550542/article/details/125102866)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
this.$router.go如何跳过锚点
this.$router.go方法用于进行页面的前进或后退操作。它接受一个参数,表示跳转的步数。当参数为正数时,表示向前跳转;当参数为负数时,表示返回(相当于back)。所以如果要跳过锚点,可以通过设置跳转步数为负数来实现。例如,使用this.$router.go(-2)可以跳过两个页面,包括锚点页面,返回到前两个页面。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [VUE this.$route 和 this.$router](https://blog.csdn.net/weixin_42371145/article/details/105289960)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文