Vue路由跳转传递参数()

需求——在单页应用中,从A页面跳转到B页面需要携带部分参数,具体操作方法有以下几种:

方法1(使用$router进行跳转):

step1:在router.js中定义携带参数的名称

{
    path: '/page/:id',  //id为你要携带的参数的名称
    name: 'Page',
    component: Page
}

step2:在A页面跳转时携带参数

let id = 0;
this.$router.push({
    path: "/page/" + id   //跳转时带上参数id
});

step3:在B页面接收参数

let id = this.$route.params.id;    //用this.$route.params.id就能接收到参数id

方法2(使用进行跳转):

step1:同方法1的第一步

step2:A页面中携带参数

 router-link跳转 

step3:B页面接收参数

let id = this.$route.params.id;    //用this.$route.params.id就能接收到参数id



你可能感兴趣的:(vue-js)