query传参
//?连接参数,&拼接参数间
<router-link to="/query?name=xm&age=18">query传参</router-link>
import NavBar from '@/components/NavBar.vue'
export default{
name:'OnePage',//给自己这个组件命名——显示在devtools
components:{
'nav-bar':NavBar
},
created(){
console.log(this.$route.query)//获取查询参数信息
}
}
params传参
{
//设置动态路由属性名
path:'/two/:name/:age',
component:()=>import('../views/TwoPage.vue')
}
//动态路由传参
<router-link to="/two/xh/18">params传参</router-link>
//获取动态路由参数信息
<span>姓名{{$route.params.name}}</span>
<span>年龄{{$route.params.age}}</span>
开启props
实现父子组件传参,待更新...