I would like to allow users to modify some parts of the css styling and make it dynamic - i.e. fetch a json
from the api and past it to the component. That is pretty much the same how styled-components allow theming by passing a json to the theme provider where each component can get the required information
Use case:
How styled-components handles theming - https://www.styled-components.com/docs/advanced
This is how I approach the feature.
My store has the "theme" substore (aka module). I extend the Vue prototype with theme state: Vue.prototype.$theme = store.state.theme
.
Then I use the theme globally in my templates:
<button class="rounded px-2" :class="$theme.main" />
Of course the store.state.theme
is a dynamic data. As soon as it changes (I assign any new JSON data to it) the entire UI redraws as needed.
// store/theme.js
state.main = "border-red";
Most helpful comment
This is how I approach the feature.
My store has the "theme" substore (aka module). I extend the Vue prototype with theme state:
Vue.prototype.$theme = store.state.theme
.Then I use the theme globally in my templates:
Of course the
store.state.theme
is a dynamic data. As soon as it changes (I assign any new JSON data to it) the entire UI redraws as needed.