DEV Community

Discussion on: Methods vs Computed in Vue

Collapse
drewclem profile image
Drew Clements

Another way to look at computed is that they can be used as dynamic data for every render.

Methods are functions that can be called as normal JS functions, but computed properties will be โ€œre-calculatedโ€ anytime some data changes in the component.

Collapse
adiatiayu profile image
Ayu Adiati Author

Thanks, Drew!

So computed is more like a method to update data to be dynamic?

When would we want to use methods or computed?

Collapse
drewclem profile image
Drew Clements

Exactly!

Another important thing to note is that computed properties are available the same as properties in your data store

So

data() {
  return {
    number: 1
  }
}
Enter fullscreen mode Exit fullscreen mode

is the same as

computed: {
  number() {
    return 1
  }
}
Enter fullscreen mode Exit fullscreen mode

Both would be available with using this.number or {{ number }}

But, if you ever needed number to update based on something else in the component, then the computed would do it auto-magically.

Thread Thread
adiatiayu profile image
Ayu Adiati Author

Thank you, Drew!!! ๐Ÿ˜ƒ