A
A
Anton Anton2017-06-03 14:26:50
JavaScript
Anton Anton, 2017-06-03 14:26:50

How to call a function that changes data from a component's event?

https://jsfiddle.net/d918pasu/
the first button changes the data directly in the attribute (it works), the second one in the handler function (documentation ) and it doesn't work.
why inside increment as this is the window object and how to change the example so that you can change the data in the handler?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-06-03
@Fragster

You are using an arrow function, it takes this from the lexical environment. You need it like this:

increment: function(num) {
            console.log(num, this);
            this.counter += num;
          }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question