Vue: Are watchers called on initial created/mount?
by Admiral Potato
HTML
<div id="app">
<watch-test
:a="a"
:b="b"
></watch-test>
</div>
CSS
body {
text-align: left;
}
JavaScript
Vue.component(
'watch-test',
{
data () {
return {
modifiedA: false,
modifiedB: false
}
},
props: {
a: Number,
b: Number
},
template: `
<pre>
a: {{a}}
b: {{b}}
Did a get set on created?: {{modifiedA}}
Did b get set on created?: {{modifiedB}}
</pre>
`,
watch: {
a () {
this.modifiedA = true
},
b: {
immediate: true,
handler () {
this.modifiedB = true
}
}
}
}
)
const vueInstance = new Vue({
el: '#app',
data: {
a: Math.random(),
b: Math.random()
}
})