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

239
Visualizações
what's the proper way to implement darkmode in VueJs with SASS using variables

What is the best implementation for dark-mode toggle feature if I am using sass with VueJS
i have a project with sass variables for the colors.

/* variables */
/* ------------- */
$bg-main: #f8f8f8;
$btn-secondary-c: #f6f6f6;
$bg-items: #fff;
$text-c-1: #625f6e;
$text-c-2: #5e5873;
$color-main: #6e6b7b;
$shadow-c: rgba(34, 41, 47, 0.05);
/* ------- */

and it has its own file and globaly scoped to my vue application

src
--components
--assets
----_variables.scss

and my Vue components are created in SFC(Single File Components) style like so

<template>
  <main>
    <div class="content-wrapper">
      <ProductsSection/>
    </div>
  </main>
</template>

<script>
import ProductsSection from "./ProductsSection.vue"
  export default {
    name: 'MainSection',
    components: {
      ProductsSection,
    },
  }
</script>

<style lang="scss" scoped>
.content-wrapper{
  background-color: $bg-main;
}
</style>

my question is what is the best implementation for this situation?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I really like to modifiy the html attribute:

// index.html
<html lang="en" data-theme="dark">
...
</html>
// App.vue
<template>
<button @click="changeTheme('light')">light theme</button>
<button @click="changeTheme('dark')">dark theme</button>
</template>

<script>
methods: {
  changeTheme(newTheme) {
     document.documentElement.setAttribute('data-theme', newTheme)
  }
}
</script>

<style lang="scss">
@import "./assets/style.scss";
</style>
// style.scss
[data-theme="dark"] {
  --bg-color1: #121416;
  --font-color: #f4f4f4;
}
[data-theme="light"] {
  --bg-color1: #f4f4f4;
  --font-color: #121416;
}
...
body {
  background-color: var(--bg-color1);
  color: var(--font-color);
}

I hope you get the idea

about 4 years ago · Santiago Trujillo 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