Reputation: 21
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? ?
Upvotes: 0
Views: 30
Reputation: 299
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')
Upvotes: 0