Answer the question
In order to leave comments, you need to log in
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
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.
Think of Computed as a class property and methods as a class method.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question