vue-路由

61 阅读1分钟
路由跳转的方式

1、声明式

<router-link to="/path"></router-link>

<router-link to="/path?a=1&b=2"></router-link>

<router-link :to="{path:'',query:{}}"></router-link>

<router-link :to="{name:'路由配置里的name',params:{}}"></router-link>

2、编程式

this.$router.push('/path')

this.$router.push({path:'/path',query:{}})

this.$router.push({name:'name',params:{}})

参数传递获取的方式

1、query

this.$route.query

2、params

this.$route.params

query和params传参的区别
queryparmas
参数是否显示在url上
参数获取方式this.$route.querythis.$route.params
path和params为什么不能一起使用

由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效。需要用name来指定页面