vue.js - 如何在 Vue 中发送颜色作为道具?
问题描述
这是我的 Button vue 对象。我想根据道具改变颜色
<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>
例如:
<Button text="Mark As Done" color="white" backgroundColor="#1cb86e"></Button>
或者
<Button text="Get Started" color="white" backgroundColor="#299ff6"></Button>
但它没有编译
解决方案
<Button text="Get Started" :style="{ 'background-color': YOURCOLORVARIABLEHERE }"></Button>
我想你可以看看那篇文章https://alligator.io/vuejs/dynamic-styles/
他们准确地解释了你想要做什么。
推荐阅读
- android - 如何从我的应用程序中链接到另一个应用程序?深度链接文档等信息
- javascript - 在猫头鹰旋转木马拖动上从兄弟姐妹中删除课程时切换课程
- java - 使用正则表达式拆分字符串不返回值
- excel - 计算一个值连续出现的最大次数
- ios - 检查用户是否使用自定义键盘
- php - laravel 中的数据比较
- objective-c - 如何在 Swift 中识别 SVG 对象内部的触摸?
- c - 如何在结构中使用联合访问 C 结构
- symfony - Symfony - 只访问他们自己的客户
- java - java.text.ParseException:无法解析的日期:“28.дек.2018”