vue router的引數傳遞

2021-10-08 07:31:13 字數 1199 閱讀 1788

(1)新建元件

新建乙個user.vue檔案,新增

(2)設定對映

開啟index.js檔案,新增如下**:

(1)新建元件:profile.vue,新增如下**

/h2>

}<

/p>

}<

/p>

<

/div>

<

/template>

export

default

;<

/script>$route.query是乙個物件,裡面是頁面傳過來的資料

(2)設定對映

開啟index.js檔案,新增如下**

const

profile=(

)=>

import

("../components/profile.vue"

);

:to=

"}" tag=

"button"

>profile<

/router-link>

例如,把原來的

:to=

"}" tag=

"button"

>profile<

/router-link>

替換為button

"profileclick"

>profile<

/button>

在methods裡新增:

profileclick()

});}

其餘的和2.一樣

vue router引數傳遞

準備工作 第一步 建立新的元件profile.vue profile 配置動態路由 傳遞引數主要有兩種型別 配置路由的格式 router id 傳遞的方式 在path後面跟上對應的值 傳遞後形成的路徑 router 123,router abc query的型別 配置路由的格式 router,也就是...

vue router傳遞引數的幾種方式

vue router傳遞引數分為兩大類 程式設計式導航傳遞引數有兩種型別 字串 物件。this.router.push home 想要傳遞引數主要就是以物件的方式來寫,分為兩種方式 命名路由 查詢引數,下面分別說明兩種方式的用法和注意事項。命名路由的前提就是在註冊路由的地方需要給路由命名如 命名路由...

vue router傳遞引數的幾種方式

引數在鏈結上顯示 this.router.push this.route.query.id 引數不在鏈結上顯示 this.router.push 注 採用params在必須要要在路由上配置name,否則undefined routes route.params.id html 取參 this.rou...