[英]How to pass values between Vue sibling components, without using 'params'?
目前,我有2個組件:
哪里:
Proyectos :這是我在App開頭顯示的組件,其中顯示了項目列表。
Reuniones :這是顯示項目會議列表的組件。
在Proyectos組件中,我發出GET
請求,該請求返回一個對象數組,即proyectos。 使用此項目列表,我可以填寫表格。
Proyecto對象結構:
{
objetivo:"",
fecha: "",
reuniones: [
{
titulo: "",
fecha: ""
},
{
titulo: "",
fecha: ""
}]
}
對於每個表格行,我都有一個項目javascript對象,我想在單擊按鈕時將其發送到Reuniones
組件。 進入Reuniones
組件后,我將執行某些操作,例如對其進行迭代。
我正在尋找一種不必通過URL發送Id
並不必重新get
對象的方法。 我想使用Proyectos組件中已經包含的對象。
我嘗試使用$emit
和$on
使用事件$on
但是由於尚未加載Reuniones組件,因此無法聽到從Proyectos組件發送的事件。
Proyectos.vue:
projectSelected (project) {
// I issue an event with the project object
this.$root.$emit ('send', project)
// I call the route 'reuniones' to load the Reuniones.vue component
this.$router.push('reuniones')
}
Reuniones.vue
this.$root.$on('send', (data) => {
console.log (data)
})
我正在尋找的行為是能夠在組件之間使用對象。
我認為您可能會考慮稱為eventBus的全局狀態,您可以在此處閱讀
它將允許您為get請求創建make there方法,並使用計算的屬性或觀察程序監視.vue實例上的更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.