Vue-59、Vue技术路由的props配置

路由的props配置

1、作用:让组件更方便的收到参数

routes:[
        {
            name:'guanyu',
            path:'/about',
            component:About
        },
        {
            path:'/home',
            component:Home,
            children:[
                {
                    path:'news',
                    component:News
                },
                {

                    path:'message',
                    component:Message,
                    children:[
                        {
                            name:'xiangqing',
                            path:'detail',
                            component:Detail,
                            //props的第一种写法,值为对象。该对象中的所有key-value都会以props形式传给detail组件
                            // props:{a:1,b:'hello'}

                            //props的第二种写法,值为布尔值,若布尔值为真,就会把该路由组件收到的所有params参数,以props的形式detail组件
                            // props:true

                            //props的第三种写法,值为函数,该对象中的所有key-value都会以props形式传给detail组件
                            props($route){
                                return {id:$route.query.id,title:$route.query.title}
                            }
                        }
                    ]
                }
            ]
        },
    ]

你可能感兴趣的:(vue,vue.js,前端,javascript)