I am working on a vue.js plugin which I hope to release within the next few weeks and I have stumbled upon something that confuses me.
When dealing with lifecycle hooks in a component,
this seems to always point to the component itself, and runtime
console.log() calls do seem to confirm it (I ran the calls from
created to test it. Despite that, the only lifecycle interface definition which specifies
(this: Vue) seems to be the
beforeCreate hook. All others do not specify it. Because of a couple of things I am doing, this means that the only hook that is behaving as expected is
beforeCreate: when I invoke the hook and use the
this keyword I am able to access any new property of the component itself. All other lifecycle hooks seem to be scoped to the component options object instead, which means I’m having to add (in both definitions and actual code) a reference to this new property I need in both the component options and the component typeof Vue generic.
Is there anyone who can help me understand why these hooks are typed differently if in fact their lexical scope is the same? What am I missing here?