Reputation: 55
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>
Upvotes: 1
Views: 41
Reputation: 5812
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>
Upvotes: 1
Reputation: 28434
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>
Upvotes: 1