I'm working a Vue project, and I'm using Vuex to manage the applications state. I've separated out the view of the app into many small layouts, as Vue components. For example I have a layout for a header
and a floating stats
panel.
I've written a custom directive for affixing the stats
panel. Currently, this works similar to Bootstrap where you set a value, and when the page scrolls beyond that point an affix
CSS class gets added to the element. This value is based on the height of the header
. As app is responsive, I would rather have this value computed from the header outerHeight
property.
Now, I can think of several ways on how to accomplish this, however I'm not sure the proper Vue way to do it.
- I could listen for resize events and have the header update it's height in the Vuex store. However, it seems poor practice to have the store manage presentation data.
- I could pass the
id
of the header to the affix directive, and usegetElementById
to check the height. But this is bypassing Vue completely. - I could add a method to the
header
to return its' height, and have the parent component that holds both theheader
andstats
panel use that to update the affix value. This however, gets messy ifheader
andstats
don't share the same parent.
Are there any other options? What would be best practice? Thanks!