1

I have a variable with color. I want to change the color of the text. How can I set this variable to v-bind: style event?

  <div class="drop" :style="'color:{{item.color}};'">
     some text
  </div>

2 Answers 2

1

Here is an example of style binding:

new Vue({
  el:"#app",
  data: () => ({ item: { color:'red' } })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
  <div class="drop" :style="{ color: item.color }">
    some text
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

@Max you're welcome, please mark the answer as the solution to close the question
1

As described in the Vue documentation here, you can use the following object syntax to bind styles:

<div class="drop" :style="{ color: item.color }">
     some text
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.