Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
Can I use v-if with style tag to choose a different source file? Or is there a better alternative?

I tried doing the example below, but it would not work. The reason why I am trying to do this is is that I would have to add way too many modifiers (--tuned) to make this work. So I was trying to source the css file based on a condition. Why would this not work and does anyone know if there is a better alternative that a million modifiers ?

<style v-if="!isTuningActive" lang="scss" src="./normal-version.scss"></style>
<style
  v-else
  lang="scss"
  src="./tuned-version.scss"
></style>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Why not separate into components? Each components with his own styling.

https://vuejs.org/guide/essentials/component-basics.html

about 4 years ago · Juan Pablo Isaza Report

0

You can compile your separate scss files into a single stylesheet (main.scss for example), then just import that main.scss file into your parent component (likely, App.vue).

This will allow you to simply switch the css class on your example above instead of trying to conditionally import stylesheets.

For example, lets say your new 'main.scss' file contains the following scss.

.tuned-version {
   p { color: red }
}

.untuned-version {
   p { color: blue } 
}

Then you'll simply need to dynamically add the class depending on your isTuningActive property.

<div :class="isTuningActive ? 'tuned-version' : 'untuned-version">
    <p>My content</p>
</div>

Helpful references:

  1. Compiling scss in Vue: https://vue-loader.vuejs.org/guide/pre-processors.html#sass
  2. Dynamic class binding: https://vuejs.org/guide/essentials/class-and-style.html#binding-html-classes
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!