A question like this:
How is it possible in vue3
after an event to call a method in another component?
Found this solution for vue2this.$refs.myComponent.myMethod()
But how is it supposed to work without "this" in vue3 + composition api?
If this is not possible then what are the alternatives?
The event itself occurs in the following code:
(for example, we can take the resize event of a component and set a task - after it, activate a method inside another component)
<Vue3DraggableResizable class="chartApp"
@resizing="print('resizing')"
>
How is it possible to implement it?
Not sure about if they are best practices but here we go.
I think you can watch your props change and trigger an event like this
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. })
You can use mitt package. Literally, you can listen and fire emit from anywhere to anywhere. Ie, parent-child, child-parent, siblings, non-siblings, etc..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.