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: { |
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 |
|
You may have a look at vueuse, it has a lot of useful composables. And you can learn from it's source code. |
That's expected, because computed properties are cached until any reactive dependency (data, props, injected values, other computed properties, etc.) changes.
Because
dateNowhas no reactive dependency, it'll always return the initial cached value.Depending of your needs, some fixes include:
dateNowfromcomputedtomethodsdateNowtodata, and update it inside of asetIntervalSee more on the docs: https://vuejs.org/guide/essentials/computed.html#computed-caching-vs-methods