Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

92
Vistas
Change App Theme during runtime using Vue

I have a Vue Js app (V2) which has a structure like so (shortened to focus on issue):

_variables.scss

$brand-theme:#F5F5F5

and loaded via sass loader as so in the vue.config.js

@import "@/assets/scss/_variables.scss";

As a result, in my various Vue components I can reference like so (this is being used in a few Vue files, not just App.Vue for example)

  .button {
    width: 100%;
    text-align: center;
    background: $brand-theme;
    ....

I have a requirement, where i need to inspect the URL, and change this value during runtime prior to rendering, by either manipulating the dom for example or another effective approach.

After some initial research, I am finding using this current structure problematic, and is leading me to re-think the approach, but I'm interested to find out if there's a way to do this with minimal code changes as is.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Assign the value to a CSS variable, on the #app element:

<style lang="scss">
  #app {
    --brand-theme: $brand-theme;
  }
</style>

In any component:

<style>
  .button {
    background-color: var(--brand-theme);
  }
</style>

Changing the value of --brand-theme variable at runtime on either the #app element or any of its descendants, will affect that element and any children reading var(--brand-theme).

Changing the value of a CSS variable from JS is easy:

document.querySelector('#app').style.setProperty('--brand-theme', newValue);
// or, on <div id="app" ref="myApp">
this.$refs['myApp'].style.setProperty('--brand-theme', newValue);

And you can also use this syntax:

<div :style="{ '--brand-theme': dataDrivenValue }" />
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda