vue傳參方法一1,路由配置 {
path: '/describe/:id',
name: 'Describe',
component: Describe
}2,使用方法 // 直接調(diào)用$router.push 實現(xiàn)攜帶參數(shù)的跳轉(zhuǎn)
this.$router.push({
// 這個id是一個變量,隨便是什么值都可以
path: /describe/${id}`,
})3,獲取方法(在describe頁面) $route.params.id 使用以上方法可以拿到上個頁面?zhèn)鬟^來的id值 vue傳參方法二1,路由配置 {
path: '/describe',
name: 'Describe',
component: Describe
}(這個地方默認配置就可以了,不用做任何的處理) 2,使用方法 this.$router.push({
name: 'Describe',
params: {
id: id
}
})父組件中:通過路由屬性中的name來確定匹配的路由,通過params來傳遞參數(shù)。 3,獲取方法(在describe頁面) $route.params.id 也用params獲取就可以了; vue傳參方法三1,路由配置 {
path: '/describe',
name: 'Describe',
component: Describe
}(默認配置) 2,使用方法 this.$router.push({
path: '/describe',
query: {
id: id
}
})(params換成了query) 3,獲取方法(在describe頁面) $route.query.id (這個地方用query還獲取id,和前面用的params獲取的區(qū)別在于,用query獲取的id值會在url中有顯示,可以看到你傳過來的值) props傳值方法父組件(table-data這個地方可以隨便取名字,不是特定的值) <div class="content">
//這個是一個普通組件,其中tabelData可以是變量,也可以是常量,和pageInfo一樣樣,這里打算傳遞兩個值過去,其實也可以用對象的方式傳過去都是可以的。
<my-table :table-data="tableData" :page-info="pageInfo" id="myTable"></my-table>
</div>子組件props: ['tableData', 'pageInfo'],
data() {
return {
tData: this.tableData,
page: this.pageInfo
}
}prop是單向綁定的,不應該在子組件內(nèi)部改變prop。不過這里的props傳過來的值會隨之父組件的值的改變而改變,是動態(tài)改變的。 $route使用小技巧1,$route.path
2,$route.params
一個 key/value 對象,包含了動態(tài)片段和全匹配片段,如果沒有路由參數(shù),就是一個空對象。 3,$route.query
4,$route.hash
5,$route.fullPath
|
|
|