$router 和 $route的區別
首先說一下 $router和 $route
this.$router 可操作路由對象,只寫對象
this.$route 路由信息對象,只讀對象
1.query
1.路由跳轉
this.$router.push({
path:'/user',
params:{
name:'abc',
age:'11'
}
})
2.接受參數
let name = this.$route.query.name;
let age= this.$route.query.age;
2.params
1.路由跳轉
this.$router.push({
name:'user',
params:{
name:'abc',
age:'11'
}
})
2.接受參數
let name = this.$route.params.name;
let age= this.$route.params.age;
總結
1.query相當於get傳參,即在瀏覽器地址欄中顯示參數。
2.params相當於post,即在瀏覽器地址欄中不顯示參數,但是如果使用params傳值的話,頁面一刷新params 的值就會消失。