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可为正整数或负整数。

相关推荐
用头发抵命1 小时前
Vue 3 中优雅地集成 Video.js 播放器:从组件封装到功能定制
开发语言·javascript·ecmascript
蓝冰凌2 小时前
Vue 3 中 defineExpose 的行为【defineExpose暴露ref变量】详解:自动解包、响应性与实际使用
前端·javascript·vue.js
奔跑的呱呱牛2 小时前
generate-route-vue基于文件系统的 Vue Router 动态路由生成工具
前端·javascript·vue.js
sp42a2 小时前
在 NativeScript-Vue 中实现流畅的共享元素转场动画
vue.js·nativescript·app 开发
柳杉2 小时前
从动漫水面到赛博飞船:这位开发者的Three.js作品太惊艳了
前端·javascript·数据可视化
TON_G-T3 小时前
day.js和 Moment.js
开发语言·javascript·ecmascript
Irene19913 小时前
JavaScript 中 this 指向总结和箭头函数的作用域说明(附:call / apply / bind 对比总结)
javascript·this·箭头函数
2501_921930834 小时前
ReactNative项目OpenHarmony三方库集成实战:react-native-appearance(更推荐自带的Appearance)
javascript·react native·react.js
还是大剑师兰特4 小时前
Vue3 中 computed(计算属性)完整使用指南
前端·javascript·vue.js