Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to apply a body {} style to specific vue component

I’m using scoped style for most of my components to not interfere with other components.
Some of my views/components need body { overflow: hidden; }, but others don’t.
I can’t use

<style scoped>
body {
  overflow: hidden;
}
...
</style>

How can i apply this style when specific components are loaded? (i am using vue router if that helps)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You may send a prop to your component like described in here: https://v2.vuejs.org/v2/guide/components-props.html

Let’s call you prop isOverflowHidden, and create .hidden class in your css.

After that, you can add your wrapper element (first tag in component) :class="{ hidden: isOverflowHidden }"

Or you can move it to a method.

If you want you can use this this action for inline-styling.

<div :style="{ overflow: (isOverflowHidden ? 'hidden' : '')}"></div>

You can read extended information in here: https://v2.vuejs.org/v2/guide/class-and-style.html#Binding-Inline-Styles

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading