- 1.params传参
- 配置路由,声明接收params参数 { path:'/home', component:Home, children:[ { path:'news', component:News }, { component:Message, children:[ { name:'xiangqing', path:'detail/:id/:title?', //使用占位符声明接收params参数,添加问号代表title可传也可不传,占位了不传递也不加?会导致跳转后的url错误 component:Detail } ] } ] }
- 传递参数 <router-link:to="/home/message/detail/666/你好">跳转 <router-link :to="{ name:'xiangqing', params:{ id:666, title:'你好' } }"
- 跳转
this.router.push(
/home/message/detail/${this.id}/${this.title}
) (不能使用path配置项,必须使用name配置) this.$router.push({ name:"detail", params:{ id:this.id, title:this.title } }) 特别注意:路由携带params参数时,若使用to的对象写法,则不能使用path配置项,必须使用name配置! - 接收参数: route.params.title 6.2 query传参
- 传递参数
<router-link:to="/home/message/detail?id=666&title=你好">跳转、
<router-link:to="/home/message/detail?id=666&title=你好">跳转
<router-link :to= path:'/home/message/detail', query:{ id:666, title:'你好' } }" - 跳转
this.router.push(
/detail?k=${this.id.toUpperCase()}&k1=${this.title.toUpperCase()}
) this.$router.push({ path:"/detail", query:{ id:this.id, title:this.title } }) - 接收参数: route.query.title 7.路由的props配置
- 传递参数 <router-link:to="/home/message/detail/666/你好">跳转 <router-link :to="{ name:'xiangqing', params:{ id:666, title:'你好' } }"
- 跳转
this.router.push(
/home/message/detail/${this.id}/${this.title}
) (不能使用path配置项,必须使用name配置) this.$router.push({ name:"detail", params:{ id:this.id, title:this.title } }) -
特别注意:路由携带params参数时,若使用to的对象写法,则不能使用path配置项,必须使用name配置!
7. 接收参数:
route.params.title
1. params传参
原创wuliGoodKid ©著作权
©著作权归作者所有:来自51CTO博客作者wuliGoodKid的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:过滤器filter的使用
下一篇:路由的props配置
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Vue3 路由传参
Vue3 路由传参
Vue路由传参 query params -
params传参与body传参区别
get是直接把参数展示在地址栏,而post请求在
json restful http get请求 post请求