0 votes
in VueJS by
How to trigger watchers on initialization?

1 Answer

0 votes
by

You can use immediate: true option in order to trigger watchers when the vue instance (or component) is being created. i.e This option will trigger the callback immediately with the current value of the expression.

watch: {
  test: {
    immediate: true,
    handler(newVal, oldVal) {
      console.log(newVal, oldVal)
    },
  },
},

Related questions

0 votes
asked Sep 10, 2023 in VueJS by DavidAnderson
0 votes
asked Sep 14, 2023 in VueJS by AdilsonLima
...