A
A
Alex2019-09-06 18:02:09
css
Alex, 2019-09-06 18:02:09

How to insert a dynamic variable?

Is it possible to insert the value of the {{safariTrue}} variable into style tags?

<input type="range"  v-model="safariTrue" >

      <style>
        h1{
        margin: {{safariTrue}};
        }
      </style>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-09-06
@astrodeep

An observer is hung on the property of the component that updates the css variable. For example :

#app h1 {
  font-size: var(--h1-font-size);
}

<div id="app" ref="app">
  <input v-model="fontSize" type="number">
  <h1>hello, world!!</h1>
</div>

data: () => ({
  fontSize: 24,
}),
mounted() {
  this.$watch(
    'fontSize',
    val => this.$refs.app.style.setProperty('--h1-font-size', `${val}px`),
    {
      immediate: true,
    }
  );
},

A
Alex, 2019-09-06
@Kozack

It is possible, but only in the attribute
https://ru.vuejs.org/v2/guide/class-and-style.html...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question