1. router-link
<router-link :to="{path:'/home'}">
<router-link :to="{name:'Home'}">
<router-link :to={name:'Home',params:{id:1}}>
2. this.$router.push(函数中跳转)
this.$router.push({path:'/home'})
this.$router.push({name:'Home'})
this.$router.push({name:'Home',params:{id:1}})
this.$router.push({path:'/home',query:{id:1}})
this.$router.push({name:'Home',query:{id:1}})
params类似post,跳转页面,url后面不会拼接参数,但是刷新页面参数会消失
query类似get,跳转页面,url后面会拼接参数,类似于?id=1,非重要性的可以这样传,重要性参数不建立用query传参。
3. this.$router.replace()(用法同上,push)
4. this.$router.go(n)
this.$router.go(n)
向前或向后跳转n个页面,n可正可负
PS:区别
this.$router.push:
跳转到指定url,并想history栈中添加一个记录,点击后退会返回到上一个页面;
this.$router.replace:
跳转到指定url路径,但是history栈中不会有记录,点击返回会跳转到上上个页面(说白了就是直接替换了当前页面);
this.$router.go(n):
向前或向后跳转n个页面,n可正可负
页面获取传递过来的参数
//params传参
html 取参:$route.params.id
script 取参:this.$route.params.id
//query传参:
html 取参:$route.query.id
script 取参:this.$route.query.id
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程