vue路由相关
在vue3中,获取路由数据不用this.$route, 而是要引入插件useRoute,useRoute().params.id;
路由中正则表达式:path:user/:id 表示是一个占位符
path: user/:id+表示一个或者多个字段
path: user/:id? 表示有一个或者没有
path: user/:id* 表示0个或者多个
path: '/:path(.*)' 可以用作所有的报错路径跳转,例如404页面,但是最好放在所有路由的最下面
在嵌套路由中,children的路径前面不需要加上斜杠
路由的分类:声明式路由,编程式路由
# 一、编程式路由跳转的模板:
- 不带参数的跳转
this.$router.push("/")
1
- 传入对象
this.$router.push({path:"/"})
1
- 传入对象带参数
this.$router.push({path:"/user/123"})
1
- params方式 类似于 post请求
this.$router.push({name:home,params:{id:12344,name:"zhangsan"}})
1
- query方式 类似于get请求
this.$router.push({path:"/home",query:{id:12344,name:"zhangsan"}})
1
# 二、replace的两种写法:
- push 写法
this.$router.push({name:home,params:{id:12344,name:"zhangsan"},repalce:true})
1
- 直接replace写法
this.$router.replace(path:"/home",query:{id:12344,name:"zhangsan"}})
1
# 三、返回上一页的两种写法:
this.$router.go(-1);
this.$router.back();
1
2
2
# 四、前进一页的两种写法:
this.$router.go(1);
this.$router.forward();
1
2
2
编辑 (opens new window)
上次更新: 2024/01/26, 05:03:22
- 01
- python使用生成器读取大文件-500g09-24
- 02
- Windows环境下 Docker Desktop 安装 Nginx04-10
- 03
- 使用nginx部署多个前端项目(三种方式)04-10