Vue路由跳轉傳遞引數()

2021-08-21 05:20:49 字數 566 閱讀 8132

需求——在單頁應用中,從a頁面跳轉到b頁面需要攜帶部分引數,具體操作方法有以下幾種:

方法1(使用$router進行跳轉):

step1:在router.js中定義攜帶引數的名稱

step2:在a頁面跳轉時攜帶引數

let id = 0;

this.$router.push();

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 通過路由頁面跳轉 引數傳遞

跳轉方式 1.this.router.push name main params post請求 name為router中定義的name 跳轉後的頁面取請求引數 this.route.params.username 2.this.router.push path params post請求 path為...

vue 路由 及 跳轉傳遞引數的總結

1 router link 2 to 8 query 12 13router link path 是要跳轉的路由路徑 推薦換成 name 值,name pathname,命名路由,兩者都可以進行路由導航 params 是要傳送的引數,引數可以直接 key value 形式傳遞 類似post quer...

路由跳轉以及傳遞引數

路由的跳轉 1.this.router.push 2.使用前需確定在定義路由時定義了name this.router.push 路由傳遞引數 1.傳遞this.router.push 獲取this.route.params.search 2.通過path攜帶的引數 傳遞this.router.pus...