vue路由傳參及獲取引數總結

2021-10-06 12:21:40 字數 1131 閱讀 4167

動態路由(這裡用來測試,傳了兩個引數username和post_id)

//路由配置

//跳轉

this

.$router.

push(/

$`,}

)

匹配路徑:/user/evan/123 

傳遞的引數:

//獲取引數

this

.$route.params.username

this

.$route.params.post_id

通過路由屬性中的name來確定匹配的路由,通過params來傳遞引數。

//路由配置

//js跳轉

this

.$router.

push(}

)

:to=

"}">

>

跳轉span

>

router-link

>

js獲取引數:this

.$route.params.id

html獲取引數:

}

使用path來匹配路由,然後通過query來傳遞引數,引數顯示在位址列上,並用?號和&號拼接的

//路由配置

//js跳轉

this

.$router.

push(}

)

"/user?id=1"

>

>

跳轉span

>

router-link

>

js獲取引數:this.$route.query.id

html獲取引數: }

引數是物件的時候使用params傳參

引數是字串拼接的時候使用query傳參

Vue路由 路由配置 傳參 獲取引數

this.route 和 this.router區別 this.route 資訊引數 query prams 傳參獲取 this.router 功能函式,go push 等方法呼叫1.匯入和使用路由 main.js import router from vue router 使用路由 vue.use...

vue route 帶引數 vue 路由傳參

v router的注意事項 使用name和params組合傳參 this.router.push 注釋 路由的配置 import vue from vue import router from vue router vue.use router export default new router 獲...

Vue路由傳參

getdescribe id 方案一,需要對應路由配置如下 很顯然,需要在path中新增 id來對應 rou ter.push 中pat h攜帶的 引數。在 子元件中 可以使用 來獲取傳 遞的引數 值。th is router.push 中path攜帶的引數。在子元件中可以使用來獲取傳遞的引數值。t...