Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
Make colors dynamic on runtime on Vuejs and Bootstrap

I have this situation : some colors like primary, secondary I should override for some users.

I have a _variables.scss file :

$primary: #4a90e2;
$light: #f2f7fd;
$secondary: #f7981c;
$success: #27ae60;
$danger: #eb6057;

Now in my App.vue I want to override these colors like this :

.....
methods: {
  changeStyle() {
     const bodyStyles = document.body.style;
     bodyStyles.setProperty('--primary-color', '#ef4d4d');
  }
}
....

but is not working. What can I try next?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're mixing SCSS variables with CSS3 variables here:

  • The variables defined in your scss files are SCSS variables i.e. $primary: #4a90e2;.
  • The variables defined in your App.vue i.e. bodyStyles.setProperty('--primary-color', '#ef4d4d'); are CSS variables.

These are entirely 2 different variables.

In order, to dynamically change your colors via JavaScript in Vue, you'll need to use CSS variables in your code. For example:

color: var(--primary-color); /* Instead of using $primary */

:root {
    --primary-color: #4a90e2
}

The problem here is you're using bootstrap and you would need to refactor your codebase to use CSS variables throughout your SCSS code, including overwriding bootstrap variables. This is not a simple task as I can tell from my experience. My approach was:

  1. Overwrite bootstrap color variables to SCSS variables e.g. $primary: var(--primary-color);
  2. Overwrite bootstrap color functions defined in functions.scss including color-contrast, tint-color, shade-color.
  3. Overwrite and refactor boostrap's buttons.scss, alerts.scss and tables.scss.

My use case was different and yours might entirely be different. A simpler approach would be to not use bootstrap (if your not using bootstrap much) but it is up to you on how you want to handle this.

Another approach could be not changing CSS variables and compiling your SCSS through Node.JS on the server to generate a css file.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda