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.
1 2 3 4 5 6 7 8 |
watch: { test: { immediate: true, handler(newVal, oldVal) { console.log(newVal, oldVal) }, }, }, |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.