1、params传参
安全性较高,类似于 post 方式
1、Category.vue
// this.$router.push({name:'*',params: { * : * }}); ==> 带参跳转
this.$router.push({name:'BuyGoods',params: {categoryName:item.categoryName}});
2、BuyGoods.vue
// this.$route.params.* ==> 通过 params 取参
this.categoryName = this.$route.params.categoryName;
3、/router/index.js
// path: '/:*' ==> 通过路径绑定参数,否则刷新时参数消失
{
path: '/BuyGoods/:categoryName',
name: 'BuyGoods',
component: BuyGoods
},
2、query传参
安全性不高,类似于 get方式,参数拼接到路径上
this.$router.push({name:'home',query: {id:'1'}})
this.$router.push({path:'/home',query: {id:'1'}})