0

Here the example: https://codesandbox.io/s/sparkling-pine-542q4?file=/src/App.vue

I created a short example. Look at the method: iAmAMethod. I use it directly in the view template section. In that method I use a reactive data prop counter but it seems that the section of that template gets re-rendered when the var counter increments. But why does this work? I thought methods are not reactive?

TatzyXY
  • 505
  • 1
  • 6
  • 13
  • Does this answer your question? [Are methods in Vue reactive?](https://stackoverflow.com/questions/59636004/are-methods-in-vue-reactive) – chash Jun 05 '20 at 17:28

1 Answers1

0

In the context of Vue, values' being reactive means that their state (properties) are tracked and their setters are intercepted to trigger re-rendering.

Related part in docs

In contrast, methods of components are not reactive, because changing their properties doesn't trigger re-rendering.

In your sample, you don't change properties of iAmAMethod method, but you change the counter data which is reactive. That's why Vue re-renders the template.

tony19
  • 125,647
  • 18
  • 229
  • 307