Simple Date.now() computed not working properly #6051
-
As the title suggests, I'm just trying to do something like this:
But I keep getting a static value (from the first-ever call to that computed). Any thoughts on this? computed: { |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
That's expected, because computed properties are cached until any reactive dependency (data, props, injected values, other computed properties, etc.) changes. Because Depending of your needs, some fixes include:
See more on the docs: https://vuejs.org/guide/essentials/computed.html#computed-caching-vs-methods |
Beta Was this translation helpful? Give feedback.
-
You may have a look at vueuse, it has a lot of useful composables. And you can learn from it's source code. |
Beta Was this translation helpful? Give feedback.
That's expected, because computed properties are cached until any reactive dependency (data, props, injected values, other computed properties, etc.) changes.
Because
dateNow
has no reactive dependency, it'll always return the initial cached value.Depending of your needs, some fixes include:
dateNow
fromcomputed
tomethods
dateNow
todata
, and update it inside of asetInterval
See more on the docs: https://vuejs.org/guide/essentials/computed.html#computed-caching-vs-methods