Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a color as a props in Vue?

This is my Button vue Object. I want to change the color based on the props

<template>
    <div class="get-started-btn flex center"
         style="cursor: pointer;
            padding: 0px 15px;
            height: 36px;
            color: {{color}} ">
            {{text}}
    </div>
</template>

<script>
    export default {
        name: "Button",
        props:{
            text:String,
            color: String,
            backgroundColor: String,
        }
    }
</script>

<style scoped>
.get-started-btn{
    background-color: {{backgroundColor}};
}
</style>

For example:

    <Button text="Mark As Done" color="white" backgroundColor="#1cb86e"></Button>

or

  <Button text="Get Started" color="white" backgroundColor="#299ff6"></Button>

But it is not compiling

like image 472
TSR Avatar asked Jan 26 '23 08:01

TSR


1 Answers

<Button text="Get Started" :style="{ 'background-color': YOURCOLORVARIABLEHERE }"></Button>

I Think you can take a look on that article https://alligator.io/vuejs/dynamic-styles/

They explain exactly what you wanna do.

like image 168
Robson Braga Avatar answered Jan 31 '23 08:01

Robson Braga