【发布时间】:2020-10-13 04:58:33
【问题描述】:
我使用 TailwindCSS 创建了一个 VueJS 按钮组件。我的目标是为该按钮组件提供一些基本样式(使用 tailwindcss 类),并在需要时选择覆盖它们(再次,使用 tailwind css 类)。
例如,这里是Button 组件的简化版本:
// Button.vue
<template>
<button class="bg-green-500 text-white py-2 px-4 rounded">
Click Me
</button>
</template>
这是我在另一个文件中使用该组件的示例:
// index.vue
<Button></Button>
<Button class="bg-red-600"></Button>
<Button class="bg-blue-600"></Button>
问题是这只是成功的一半。也就是说,bg-blue-600 确实覆盖了我在Button.vue 中设置为默认值的bg-green-500。但是bg-red-600确实不覆盖背景颜色(大概是因为bg-red-600在css源代码中出现得更早。
因此,我想知道如何正确设置它?也就是说,我怎样才能给Button 组件一些基本样式(同样,使用tailwind css 类),同时还提供使用tailwind css 类覆盖这些样式的选项。
谢谢。
【问题讨论】:
标签: vue.js vuejs2 vue-component tailwind-css