I have a question about passing variables to nested components.
I have 3 components:
- Parent
- Child
- SubChild
and they have a shared variable (call it myVar).
Suppose I don't want to use Vuex. My question is what is a better way of passing myVar from Parent to SubChild.
First way
- (In Parent) I am passing myVar to Child by props option. (it's common).
- (In Child) I am passing the prop option myVar directly to SubChild as its prop option.
Second way
- (In Parent) I am passing myvar to Child by props option. (it's common).
- (In Child) I am cloning the prop option myVar to local variable (call it myLocalVar) and passing the cloned variable myLocalVar to SubChild as its prop option.
I prefer the second way, but I have to create watches
- To handle changes from Parent to myLocalVar.
- To handle changes from Child to emit it to Parent.