篇首语:本文由小编为大家整理,主要介绍了Vue中路由的queryparams参数。如何传值如何取值。详细过程+图解相关的知识,希望对你有一定的参考价值。
<!-- 跳转并携带query参数,to的字符串写法 --> <router-link :to="/home/message/detail?id=666&title=你好">跳转</router-link> <!-- 跳转并携带query参数,to的对象写法 --> <router-link :to=" path:/home/message/detail, query: id:666, title:你好 " >跳转</router-link>
$route.query.id $route.query.title
可以简化路由的跳转。
path:/demo, component:Demo, children:[ path:test, component:Test, children:[ name:hello //给路由命名 path:welcome, component:Hello, ] ]
<!--简化前,需要写完整的路径 --> <router-link to="/demo/test/welcome">跳转</router-link> <!--简化后,直接通过名字跳转 --> <router-link :to="name:hello">跳转</router-link> <!--简化写法配合传递参数 --> <router-link :to=" name:hello, query: id:666, title:你好 " >跳转</router-link>
<hr>
path:/home, component:Home, children:[ path:news, component:News , component:Message, children:[ name:xiangqing, path:detail/:id/:title, //使用占位符声明接收params参数 component:Detail ] ]
<!-- 跳转并携带params参数,to的字符串写法 --> <router-link :to="/home/message/detail/666/你好">跳转</router-link> <!-- 跳转并携带params参数,to的对象写法 --> <router-link :to=" name:xiangqing, params: id:666, title:你好 " >跳转</router-link>
$route.params.id $route.params.title
让路由组件更方便的收到参数
name:xiangqing,path:detail/:id,component:Detail,//第一种写法:props值为对象,该对象中所有的key-value的组合最终都会通过props传给Detail组件// props:a:900//第二种写法:props值为布尔值,布尔值为true,则把路由收到的所有params参数通过props传给Detail组件// props:true//第三种写法:props值为函数,该函数返回的对象中每一组key-value都会通过props传给Detail组件props(route)return id:route.query.id,title:route.query.title
<router-link>
的replace属性push
和replace
,push
是追加历史记录,replace
是替换当前记录。路由跳转时候默认为push
replace
模式<router-link replace .......>News</router-link>
以上是关于Vue中路由的queryparams参数。如何传值如何取值。详细过程+图解的主要内容,如果未能解决你的问题,请参考以下文章