簡體   English   中英

如何使用 Vue 路由器將數據傳遞給另一個組件?

[英]How do I pass data to another component using Vue router?

目前,我有一個在頁面上呈現的組件,當我控制台記錄組件內的this.$router變量時,我看到完整路徑屬性等於 '/hello/reports?report=3849534583957' 和路徑屬性等於只是'/hello/reports/'。

在一個單獨的組件中,我試圖通過使用將數據傳遞給上面的組件

this.$router.push({path:`/hello/reports?report=3849534583957`, params: {data: 'hey'}})`

但是,當我嘗試查看 vue devtools 中的參數或通過控制台記錄this.$route.params.data時,它返回我未定義。

我相信我做的一切都是正確的,請幫助我了解我哪里出錯了。 我已經嘗試在 push 方法中只用常規路徑屬性的值替換完整路徑屬性的值。 謝謝

路由器參數 map 為路由器配置中設置的值。

const router = new VueRouter({
  routes: [{ path: '/user/:id', component: User }]
})

id是此路由的有效參數。

在官方文檔中查找更多信息: https://router.vuejs.org/guide/essentials/dynamic-matching.html#dynamic-route-matching

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM