[Vuejs]-Vuejs Arrow Function not triggering second statement

2👍

What is going on here is this a limitation with lambdas? Can you only trigger one statement per lambda? Or does this have to deal with scope once an alert is fired?

It’s neither.

An arrow function keeps this bound to the context it was when the arrow function was created. In this case, this is not the vue instance. It’s probably window

A function declared on an object using the function keyword (or the ES6 object shorthand style) will normally have this bound to the object on which the function is declared.

That’s why you can access this.activated on alertyou but not alertme

You’ll want to use the same syntax as alertyouto declare the alertme method.

1👍

Change alertme: () => { alert('Clicked'); this.activated = false; } to alertme() { alert('Clicked'); this.activated = false; }. You can see a working example here

Leave a comment