Skip to content

Simple Date.now() computed not working properly #6051

Discussion options

You must be logged in to vote

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:

  • moving dateNow from computed to methods
  • adding dateNow to data, and update it inside of a setInterval

See more on the docs: https://vuejs.org/guide/essentials/computed.html#computed-caching-vs-methods

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Namidas
Comment options

Answer selected by LinusBorg
Comment options

You must be logged in to vote
1 reply
@Namidas
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants