this.$router.push({name:'/xx/xx',query: {id:'1'}});
this.$router.push({name:'/xx/xx',params: {id:'1'}});
this.$router.push({path:'/xx/xx',query: {id:'1'}});
this.$router.push({path:'/xx/xx',params: {id:'1'}});
1.query方式傳參和接受參數
this.$router.push({
path:'/xxx'
query:{
idname:id
}
})
接收的方式:this.$route.query
query類似於ajax中get傳參,即在瀏覽器地址欄中顯示參數。
2.params方式傳遞參數
this.$router.push({
name:'路徑名稱'
query:{
idname:id
}
})
接收的方式:this.$route.params
params則類似於post,即在瀏覽器地址欄中不顯示參數。
注意:
- 接收是用this.$route,不是this.$router
- params用的是name進行的傳遞,這就意味着在router的js文件里,要給其加上name屬性

