vue $router路由跳转方式 --带参数
方法: push()和replace()跳转this.$router.push()和this.$router.replace()用法一致1.不带参数this.$router.push('/login')//this.$router.replace('/login')this.$router.push({name:'login'})//this.$router.replace({name:'logi
·
方法: push()和replace()跳转
this.$router.push()和this.$router.replace()用法一致
1. 不带参数
this.$router.push('/login') //this.$router.replace('/login')
this.$router.push({name:'login'}) //this.$router.replace({name:'login'})
this.$router.push({path:'/login'}) //this.$router.replace({path:'login'})
2. 带参数-query传参
this.$router.push({name:'login',query: {key:'xiong'}}) //this.$router.replace({name:'login',query: {key:'xiong'}})
this.$router.push({path:'/login',query: {key:'xiong'}})
//this.$router.replace({path:'/login',query: {key:'xiong'}})
接收: this.$route.query.key//注意这里是$route,不要写成$router
3. params传参
this.$router.push({name:'login',params: {key:'xiong'}})
// 路由需要配置 path: "/home/:key" 或者 path: "/home:key" ,
// 不配置path ,第一次可请求,刷新页面key会消失
// 配置path,刷新页面key会保留
接收: this.$route.params.key
query/params区别
query类似 get, 跳转之后页面 url后面会拼接参数,类似?key=xiong&val=22, 非重要性的可以这样传, 密码之类还是用params刷新页面id还在
params类似 post, 跳转之后页面 url后面不会拼接参数 , 但是刷新页面id 会消失
this.$router.go(n)
this.$router.push()
跳转到指定路径,history栈中添加一个记录,点击后退会返回到上一个页面
this.$router.replace()
跳转到指定路径,history栈中没有记录,点击返回跳转到上上个页面
更多推荐
所有评论(0)