I'm creating a component with Vue.js.

When I reference this in any of the the lifecycle hooks (created, mounted, updated, etc.) it evaluates to undefined:
mounted: () => { console.log(this); // logs "undefined" }

The same thing is also happening inside my computed properties:
computed: { foo: () => { return this.bar + 1; } }

I get the following error:
Uncaught TypeError: Cannot read property 'bar' of undefined

Why is this evaluating to undefined in these cases?

Write your answer...

Never miss a post from Aditya Agrawal, when you sign up for Ednsquare.