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?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…