vue页面跳转

1、router-link跳转

复制代码
1.不带参数
<router-link :to="{name:'home'}"> 
<router-link :to="{path:'/home'}">

 
2.带params参数
<router-link :to="{name:'home', params: {id:123456}}"> 

 
3.带query参数
<router-link :to="{name:'home', query: {id:123456}}"> 

2、this.$router.push()

复制代码
1. 不带参数
this.$router.push('/home')
this.$router.push({name:'home'})
this.$router.push({path:'/home'})
 
2. query传参 
this.$router.push({name:'home',query: {id:'123456'}})
this.$router.push({path:'/home',query: {id:'123456'}})

 
3. params传参
this.$router.push({name:'home',params: {id:'123456'}})

跳转到指定url路径,并向history栈中添加一个记录,点击后退会返回到上一个页面。

query和params区别

query类似get, 跳转之后页面url后面会拼接参数,类似?id=123456, 非重要性的可以这样传, 密码之类还是用params刷新页面id还在

params类似post, 跳转之后页面url后面不会拼接参数, 但是刷新页面id会消失。

3、this.$router.replace()

用法同上,和第2个的this.$router.push方法一样。

跳转到指定url路径,但是history栈中不会有记录,点击返回会跳转到上个页面 (直接替换当前页面)。

4、this.$router.go(n)

复制代码
<button @click="upPage">上页</button>
<button @click="downPage">下页</button>


// 上页
upPage() {
    this.$router.go(-1);  // 后退一步记录,等同于 history.back()
},

// 下页
downPage() {
    this.$router.go(1);   // 在浏览器记录中前进一步,等同于 history.forward()
}

向前或者向后跳转n个页面,n可为正整数或负整数。

相关推荐
ruanno_top15 小时前
选中一项后,焦点掉回了页面顶部:三个弹层的焦点还原
vue.js
小厨勺子16 小时前
我用AIUI给Rokid眼镜做了个随身换算智能体
javascript
夕水17 小时前
我用trae重构了ew-color-picker,一个插件化架构的现代颜色选择器
前端·javascript·开源
tryCbest17 小时前
Vue3——第 17 篇:模板引用(ref)与组件实例——操作 DOM 的正确姿势
vue.js·前端搭建
头发还在的女程序员18 小时前
Java在线租房系统源码解析:Spring Boot+Vue 3+UniApp房源管理与预约看房方案
java·vue.js·spring boot·租房小程序·租房系统·租房软件
FYKJ_201018 小时前
springboot同人周边订单管理系统48955-计算机毕业设计、课程设计
java·javascript·vue.js·spring boot·django·php·课程设计
总要学点什么18 小时前
第106篇:三维特效-流动线效果——让一颗光点沿整条线一路滚到头
开发语言·javascript·ecmascript·gis·webgl·材质·cesium
2分钟速写快排1 天前
孔乙己的茴字有多少种写法?|AI 对话实时通信的三种实现
前端·javascript·github
梯度下降者1 天前
Nuxt框架
vue.js·服务端渲染·全栈开发·混合渲染·nuxt框架
用户0044729538251 天前
练歌镜:让眼镜听懂“循环这一句”
javascript