E
E
Evgeny Zhurov2020-05-28 14:21:52
Vue.js
Evgeny Zhurov, 2020-05-28 14:21:52

How to make styles in .vue file disable/enable by condition?

Good afternoon. There is a task to make styles of components disconnected. For example, we pass is_stylized: false to props, and styles should not be applied. Roughly speaking, to work something like:

<style lang="scss" scoped v-if="is_stylized"></style>
But of course, that doesn't work. How do you make sure that this is exactly what happens? Maybe not through props, but somehow...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Pautov, 2020-05-28
@bootd

Well, make a class by condition from props. What the fuck are you suffering

<template>
  <div
    :class="{
      myClass: isStylized
    }"
  >

  <div>
</template>

<script>
  export default {
    props: {
      isStylized: {
        type: Boolean,
        default: true
      }
    }
  }
</script>

S
szanislo, 2020-05-28
@szanislo

Full article on the official resource how to work with it
Working with classes and styles

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question