TSR*_*TSR 3 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}}
</div>
</template>
<script>
export default {
name: "Button",
props:{
text:String,
color: String,
backgroundColor: String,
}
}
</script>
<style scoped>
.get-started-btn{
background-color: {{backgroundColor}};
}
</style>
Run Code Online (Sandbox Code Playgroud)
例如:
<Button text="Mark As Done" color="white" backgroundColor="#1cb86e"></Button>
Run Code Online (Sandbox Code Playgroud)
或者
<Button text="Get Started" color="white" backgroundColor="#299ff6"></Button>
Run Code Online (Sandbox Code Playgroud)
但它没有编译
小智 6
<Button text="Get Started" :style="{ 'background-color': YOURCOLORVARIABLEHERE }"></Button>
Run Code Online (Sandbox Code Playgroud)
我想你可以看看那篇文章https://alligator.io/vuejs/dynamic-styles/
他们准确地解释了你想要做什么。
| 归档时间: |
|
| 查看次数: |
2732 次 |
| 最近记录: |