In Vue, provide can pass values to child components

provide('data',ref("I am data for child components"))

Subcomponents can use inject to get the value.

How to get the data in the parent component? ?

1

There are 1 best solutions below

0
Kan Robert On

Normal pass by value:

let data = ref("I am data for child components");
provide('data',data);//This way the parent component can get 

it and the child component can get it too

Transfer Function:

let children = ref('')
function data(val){

children.value = val;//Get the value passed by the child component
}
provide('data',data);

Sub: let getData = inject('data',data) data is a function, you can getData('data for father')