I am looking to utilize Vue data/prop variables within the <style>
tag located at the bottom of my component.
For example, suppose I have a component structured like this:
<template>
<div class="cl"></div>
</template>
<script>
export default {
data () {
return {
val: '30px'
}
}
..
}
</script>
<style>
.cl p{
height: 30px;
}
</style>
I want to find a way to incorporate the val data variable into the <style></style>
in order to style accordingly.
I understand that using
<div :style="{'height':val}"></div>
allows for styling based on Vue props/variables but it only sets the style for that specific div. I aim to apply a consistent style to all p tags or any other tags inside my div by declaring it as a class.
One approach is defining a class and toggling its activation (true/false) value, such as :
<div :class="{'cl': someBoolVariable}"></div>
. However, what if I require the height to be dynamic, adjusting based on some calculation/value passed from the parent component?
Ideally, I am seeking something along these lines:
<style>
.cl p {
height: val;
}
</style>
If anyone has suggestions on how to achieve this, or a simple workaround to make it possible, kindly share.