Home

Issue: 2086

Feed the store with window data on application start

[issue link]

Hey there,

I am setting some values on my store based on the window width. At the moment I am doing this from my layout, with a mounted function and then also attaching a resize listener to update these.
One example is setting isMobile based on the window width.
Then I have components or computed properties which depend on isMobile, this works but there is a small delay because it seems that the value is assigned a bit late.

My thought was to get the window width before my application starts and then somehow pass it to the store.

I tried with a plugin like this:

export default ({store}) => { if (process.browser) { let ww = window.innerWidth store.commit('IS_MOBILE', ww < 768) } }

but I get these errors:

vue-error

Maybe I’m thinking it in the wrong way? Any help appreciated.

This question is available on Nuxt.js community (#c1851)