命名路由:给路由取名
在index的routes中 path前 写一个name:'hello',
可以在跳转的时候简化一些编码
就是在router-link的 to里边 可以用 :to="{name:'hello'}"
相当于是 to='/demo/test/hello'
-----------------------------params参数-----------------
和query用法大体类似
首先需要在路径上占位
在index文件中 path:'detail/:id/:title' //使用占位符声明接收params参数
一般都是在router-link中的to中写入
params:{
xxxxxxxxxxx
}
-------------------------
query和params的区别
如果用params 那么只能用name
query name和path都可以用
使用方法:(接收参数)
$route.params.id
$route.params.title
-------------------------路由的props的配置---------------
为了解决使用问题参数名太长的问题
类似:$route.params.id
1.在index相应的组件中
写入props:true //props的第二种写法
若为true则把路由组件收到的所有params函数,以props的形式传给该组件
接收方法:
在该路由对应的vue文件中
props['id','title']
2.index相应的路由下
props($router){
return {id:$route.query.id,title:$route.query.title}
}
接收方法:
在该路由对应的vue文件中
props['id','title']
解构赋值的连续写法 //不推荐
props({query }) //获取props里边的query
{
return{ id:query.id,title:query.title }
}
props({query:{id,title}}) { //获取到props中的query中的id和title
return {id,title}
}