首页 > 其他分享 >window.location.href和this.$router.push区别

window.location.href和this.$router.push区别

时间:2022-09-27 14:36:46浏览次数:48  
标签:window href location 跳转 push router pushState history

使用location.href=’/url’来跳转,简单方便,但是刷新了页面;
使用history.pushState(’/url’),无刷新页面,静态跳转;

引进router,然后使用router.push(’/url’)来跳转,使用了diff算法,实现了按需加载,减少了dom的消耗。
其实使用router跳转和使用history.pushState()没什么差别的,因为vue-router就是用了history.pushState(),尤其是在history模式下。

this.$router.push(path) 介绍:

- 跳转到指定URL,向history栈添加一个新的记录;
- 点击后退会返回至上一个页面

标签:window,href,location,跳转,push,router,pushState,history
From: https://www.cnblogs.com/Galaxy1/p/16734423.html

相关文章