4

i am working on a Vuejs project and, I would like to import ".scss" files dynamicly during script. for example I would like to import "assets/sass/style.scss" in the style tag without writing any codes in the style tag. I would like to handle it in the script section.

check below codes:

<style  lang="scss">
  @import "assets/sass/plugins";
  @import "assets/sass/style";

  //@import "assets/sass/plugins.dark";
  //@import "assets/sass/style.dark";
</style>

This styles are retaled to dark mode and light mode. sometimes i need to use light and sometimes dark and i can not use both at the same time. so need wtite script to do this.

1 Answer 1

2

Try to wrap CSS imports in a class:

<style lang="scss">
  .light {
    @import "assets/sass/plugins";
    @import "assets/sass/style";
  }
  .dark {
    @import "assets/sass/plugins.dark";
    @import "assets/sass/style.dark";
  }
</style>

And then use class binding for that class:

<div :class="isDark ? 'dark': 'light'">
    ...
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

tnx for your replying. it doesn't work. because those imports are global and so many components are using them (style tag is not scoped). i have to add dark and light class to all tags to work.
@Mohsen Dehghani hey mate, maybe if you put that class bind in app.vue on div with id="app" and not scope global div? Maybe if you use vuex create global state isDark...
yes. i have done the exactly thing what you said. but it is worked with some components not all of them. and font not loaded too for any of them. haven't you got any solution for importing with script?
I think that maybe the problem is in your components scoped styles which overrides global ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.