vue路由细节探讨
1.使用router-link 不会让页面刷新,使用a标签会使页面刷新。
2.router-link 里面的to="/路由地址" tag=""自定义标签" 默认为a标签,linkActiveClass 可以更改默认类名。
3.在 HTML5 history 模式下,router-link 会拦截点击事件,让浏览器不在重新加载页面。
4.当你在 HTML5 history 模式下使用 base 选项之后,所有的 to 属性都不需要写(基路径)了。
5.传参:
<router-link :to="{ path: 'register', query: { userId: 'xxx' }}">Register</router-link>
<router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>
6.二级路由和多级路由配置就在当前路由下面配置children:[{path:"xxxx",name:"xxx",component:xxx}]
7.路由全局守卫(路由钩子函数)
router.beforeEach((to,from,next)=>{
console.log("跳转前")
//判断stroe.getter.isLogin ==== false
// if(to.path=="/login" || to.path == "/register"){
next();
// }else{
next("/login")
// }
})
8.路由后置钩子函数
router.afterEach((to,from)=>{
console.log("跳转后")
})
9.路由独享守卫:
就是在配置路由界面加上
router.beforeEach((to,from,next)=>{
console.log("跳转前")
})
10.组件内守卫
进入时候
beforeRouterEnter:(to,from,next)=>{
next(vm=>{
alert("vm.name")
})
离开时候
beforeRouterEnter:(to,from,next)=>{
if(confirm("确定要离开么?") == true){
next()
}else{
next(false)
}
}
最新文章
- 在64位系统上不能安装Matlab notebook的解决方案
- VSFTPD配置TLS/SSL
- tomcat异常: Cannot get a connection, pool exhausted
- 常见行为:仿真&;重力&;碰撞&;捕捉
- C#.net 获取当前应用程序所在路径及环境变量
- hdu 4447 Yuanfang, What Do You Think?
- HttpServletRequest 的使用
- ZOJ 2283 Challenge of Wisdom
- 【设计模式:单例模式】使用单例模式加载properties文件
- 如何获取fragment里的控件
- CSS---input标签注意
- Web监听器导图详解(转)
- Educational Codeforces Round 22.B 暴力
- word文档转pdf,支持.doc和.docx,另附抽取pdf指定页数的方法
- ip访问网站和localhost访问网站中top使用
- cornerstone 使用-图标含义-分支-合并
- .yml文件格式
- path-control demo js
- 计算MySQL的内存峰值公式 (转)
- 关于supervisor无法监控golang代码的解决方法
热门文章
- 契约式设计 契约式编程 Design by contract
- 清空sql 日志
- How to Execute Page_Load() in Page&#39;s Base Class?
- 从sp_executesql中返回table型数据及动态SQL语句的参数化查询
- Linux共享内存(二)
- python标准输入,标准输出,标准错误
- C++中continue
- 清除当前文件夹下.svn文件的方法
- 微信公众平台——基础配置——服务器配置:PHP版
- E20180219-hm-xa