I am getting my head round the different ways of communicating between components and their children, grandchildren, etc., and have been taking a look at provide/inject for the first time. I can get this to work fine without being reactive (which I know is the way it is designed), but cannot get reactive behaviour using an observed object. Let's say I have a nested object structure, A > B > C, where A is the grandparent of C. I have a data property of A, 'page', changes to which I would like to observe in grandchild C. If I just provide 'page' in A and inject 'page' in C, it's not reactive (by design). I thought if I did something like this instead it might work:
In provider:
data() {
return {
page: null,
obj:{currentPage:this.page}
}
},
provide(){
return {
obj: this.obj
}
}
In child or grandchild:
inject: ['obj']
But it doesn't. If I try to use obj.currentPage in the grandchild component, it is undefined.
I'm sure this is pretty straightforward. What am I not getting?