Skip to content

路由的 params 参数

配置路由,声明接收 params 参数

js
{
  path:'/home',
  component:Home,
  childern:[
    {
      path:'news',
      component:News,
    },
    {
      path:'message',
      component:Message,
      childern:[
        {
          name:'xiangqing',
          path:'detail:id/:title',//使用占位符声明接收params参数
          component:Detail
        }
      ]
    },
  ]
}

传递参数

js
//跳转并携带params参数,to的字符串写法
<router-link :to="/home/message/detail/666/你好">跳转</router-link>
//跳转并携带params参数,to的对象写法
<router-link
  :to="xiaoqing"
    params="{
      id:666,
    	title:'你好'
    }">跳转</router-link>

接收参数

提示

  • $router.params.id
  • $router.params.title