[英]How to call child component method from parent component method only after subscribing httpClient observables?
[英]How to call a method in a child (or any other) component after an event in the parent?
像這樣的一個問題:
在一個事件之后如何在vue3
中調用另一個組件中的方法?
為 vue2 找到了這個解決方案this.$refs.myComponent.myMethod()
但是在 vue3 + 組合 api 中,如果沒有“這個”,它應該如何工作?
如果這是不可能的,那么有什么替代方案?
事件本身發生在以下代碼中:
(例如,我們可以獲取一個組件的 resize 事件並設置一個任務 - 在它之后,激活另一個組件內的方法)
<Vue3DraggableResizable class="chartApp"
@resizing="print('resizing')"
>
怎么可能實現它?
不確定它們是否是最佳實踐,但在這里我們是 go。
我認為你可以看到你的道具發生變化並觸發這樣的事件
import { watch, toRefs } from 'vue' const props = defineProps({ yourReactiveProp: Boolean }) const { yourReactiveProp } = toRefs(props) // this is reactive watch( () => yourReactivePropn.value, (newVal) => { yourMethod() // you can pass the new value also. })
您可以使用手套package。 從字面上看,您可以從任何地方到任何地方收聽和發射。 即,父子,子父,兄弟姐妹,非兄弟姐妹等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.