W
W
wipe00092021-06-23 09:18:07
Vue.js
wipe0009, 2021-06-23 09:18:07

How to make css variable reactive and dependent on Vue js variable?

Hello, while styling a linear gradient, I want to change the fill tones using a variable example

--litters-range: 25%;
background: linear-gradient(
          to right,
          white var(--litters-range),
          rgba(87, 87, 87, 0.46) var(--litters-range)
        );

How can I compose a computed property that will change the css variable depending on the Vue js variable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2021-06-23
@Kozack Vue.js

Option 1:

<template>
  <div :style="{ '--litters-range': myComputedProperty }"></div>
</template>

Option 2:
<style>
  div {
    background: linear-gradient(
        to right,
        white v-bind(myComputedProperty),
        rgba(87, 87, 87, 0.46) v-bind(myComputedProperty)
    );
  }
</style>

https://github.com/vuejs/rfcs/pull/231

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question