When enter a page for the first time, SSR and SPA perform different.
I know, SSR will return a static HTML for the first time, then Hydrate(active) the page.
But still I can't figure out
For SSR:
export default {
asyncData() {
return {
paramA: {}
}
},
data() {
return {
paramB: {}
}
},
watch: {
paramA: function(newValue) {
console.log('paramA', newValue) // won't print unless 'immediate: true'
},
paramB: function(newValue) {
// Here is what i'm confusing
// will print whether 'immediate: true' or not, **Why?**
console.log('paramB', newValue)
}
}
}
For Pure Vue SPA:
export default {
data() {
return {
paramC: {}
}
},
watch: {
paramC: function(newValue) {
console.log('paramC', newValue) // won't print unless 'immediate: true'
}
}
}
@fxxjdedd I believe that's because when paramB is merged into the object in SSR, the watcher is already set up.
I think because in SSR there's a state object sent from the server, which is then applied (causing the watcher to fire)
data() asyncData() on serverdata() on serverasyncData on client (?)data() on clientso we can not watch data in ssr?
@hitao123 Of course you can. With all normal Vue usage there won't be any difference.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I think because in SSR there's a state object sent from the server, which is then applied (causing the watcher to fire)
SPA:
data()SSR:
asyncData()on serverdata()on serverasyncDataon client (?)data()on client