Vue.js 如何在Vue中将颜色作为道具发送?
这是我的Button vue对象。我想根据道具改变颜色Vue.js 如何在Vue中将颜色作为道具发送?,vue.js,vue-component,Vue.js,Vue Component,这是我的Button vue对象。我想根据道具改变颜色 <template> <div class="get-started-btn flex center" style="cursor: pointer; padding: 0px 15px; height: 36px; color: {{color}} "> {{text}} </di
<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>
{{text}}
导出默认值{
名称:“按钮”,
道具:{
文本:字符串,
颜色:字符串,
背景颜色:字符串,
}
}
.开始使用btn{
背景色:{{backgroundColor}};
}
例如:
<Button text="Mark As Done" color="white" backgroundColor="#1cb86e"></Button>
或
但它不是在编译
<Button text="Get Started" :style="{ 'background-color': YOURCOLORVARIABLEHERE }"></Button>
我想你可以看看那篇文章
他们准确地解释了你想做什么。检查此链接是否有帮助:
<Button text="Get Started" :style="{ 'background-color': YOURCOLORVARIABLEHERE }"></Button>