Watchers not triggered on initialization | immediate vue watch
Hi,Firstofall,vueisreallygreat!I’veencounteredsomeproblemsusingwatchers.Itseemsthatwatchersarenottriggeredwhenthevueinstance(orcomponent)isbeingcreated.Onlysubsequentchangesoftheproptriggerthewatchfunction.Togetthingsworking(toavoidmissingtheinitialvalueoftheprop)Ihavetorepeatthewatchfunctioninthemountedhook:module.exports={props:["test"],watch:{test:function(value){if(value){//Dosomestuffthis.initSomething();}}},methods:{initSomething:function(){}},mounted:function(){if(this.test){//Dothesa...
Hi,
First of all, vue is really great!
I’ve encountered some problems using watchers.
It seems that watchers are not triggered when the vue instance (or component) is being created. Only subsequent changes of the prop trigger the watch function.To get things working (to avoid missing the initial value of the prop) I have to repeat the watch function in the mounted hook:
module.exports = { props: ["test"], watch: { test: function(value) { if (value) { //Do some stuff this.initSomething(); } } }, methods: { initSomething: function() { } }, mounted: function() { if (this.test) { //Do the same stuff as above this.initSomething(); } } };Is this behaviour intended? And if so, why? Shouldn’t initializing the prop be regarded as a change of the prop (prop changes its value from undefined to someth...