Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

How can I dynamically switch light/dark mode


I have demo 2 up and running. I cannot toggle the dark theme by adding "dark-mode" to the body's class list.

I've also tried to load both styles (dark and light) in App.vue. At first it seems like that this works but this also seems to break a lot of things.

What would be the recommended way of switching modes in demo 2?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


Hi Florian!

You can wrap dark and light styles with some class and then switch a class when the user changes a theme mode.



I have tried that. It breaks the style. I wrapped the imports in their own classes and applied either light or dark class to body. It does not really work. Diagram colors break,etc.



Working with direct @import
<img src=" width="600" />

Not working with @import nested like this


html {
@import ...
}


<img src=" width="600" />



Hi Florian!

By using this approach some classes might not work.

Another solution that you can use is to add a webpack script to bundle dark and light mode sass separately and then connect them directly to public/index.html file.

Then you should be able to toggle these style files from your javascript code.

Check examples in stackoverflow page below:


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(