用vue-cli搭建的vue的项目,里面都是自带的href跳转,我想问,href跳转和router跳转有什么区别????????有点是什么?
vue-router is the official router for Vue.js. It deeply integrates with Vue.js core to make building Single Page Applications with Vue.js a breeze. Features include:
Nested route/view mapping
Modular, component-based router configuration
Route params, query, wildcards
View transition effects powered by - Vue.js' transition system
Fine-grained navigation control
Links with automatic active CSS classes
HTML5 history mode or hash mode, with - auto-fallback in IE9
Customizable Scroll Behavior
写了不是很久但是我感觉最直面的方便是在于
一、最简单的,可以跳转到path:xxx啊,name:xxx啊,另外想要使用hash模式和history模式你只需要改变一个变量即可,不用手动去改跳转链接啊。
二、路由钩子,有这部分钩子,你可以设置在路由之前要干什么,路由结束后干什么
三、可以直接使用自带 route 读取参数,如/bar/:id,可以直接通过 this.$route.query 获取到 :id 不是么
vue-router
毕竟是全家桶里的东西,里面会封装好各种在操作路由时的一些常用动作,比如滚动到某个位置。还有非常有用的钩子函数。
另外,它模拟了h5的 history api,用起来会比较顺手。
在浏览器中展示的时候,最终会编译为 <a href=''></a>
这样的形式
2 回答4.9k 阅读✓ 已解决
4 回答4.5k 阅读✓ 已解决
4 回答2k 阅读✓ 已解决
4 回答2.1k 阅读✓ 已解决
3 回答4.9k 阅读
3 回答1.8k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
其实顺便点进去里面vue-router的文档看不就可以了么~简单来看可以说前者刷新页面(一般)后者不刷新页面(用的是局部刷新…吧)