Web前端
Vue同一路由跳转页面不刷新解决方案及注意事项
默认情况跳转至同一个路由地址(path相同,即使params或者query不同也算同一个)的话,只是浏览器url变了,其它是不会发生任何变化,这就是网友常说的“同一页面跳转,路由变了但是页面不刷新”。 我们可以写两个测试页面 // goNext.vue <template> <section> <button @click="goNext">跳转至自身</button> <button @click="goBack">跳转至goBack</button> </section> </template> <script> export default { name: 'goNext', mounted() { console.log('组件生命周期 mounted', 'goNext'); this.showInfo(); }, beforeDestroy() { console.log('组件生命周期 beforeDestroy-> ', 'goNext'); }, beforeRouteEnter(to, from, next) { console.log('路由生命周期 beforeRouteEnter-> ', 'goNext'); next(); }, beforeRouteLeave(to, from, next) { console.log('路由生命周期 beforeRouteLeave-> ', 'goNext'); Read more…