V
V
Vitya Podpriklopolny2019-04-11 19:01:33
Vue.js
Vitya Podpriklopolny, 2019-04-11 19:01:33

What is the difference between computed and methods in Vue?

I re-read a bunch of articles, including the documentation, and I just can’t understand how computed differs from methods .
More precisely, I see in the example how they differ, but I cannot understand why this happens.
for example , why does the drawRes function work
when you click on turn on or swap colors ? I don't call her anywhere. Why is this happening and why is it necessary? By adding this function to computed, the problem goes away. And most importantly, you cannot pass parameters in computed. I can't understand anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Boltnev, 2019-05-01
@megamage

If it is very short and simple, without understanding the essence:
methods - we use in 90% of cases for eventHandler. Clicking the button calls the method. That is, manual initialization of any action.
computed - used to return data or properties. In computed properties, as a rule, there is a return, which returns something. For example, you need to get an array of data from the vuex store in the component, which would later be used in the local component. This is where computed comes to the rescue, which returns this.$store.state.array.

I
Ihor Bratukh, 2019-04-11
@BRAGA96

Think of Computed as a class property and methods as a class method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question