【发布时间】:2021-03-29 23:10:45
【问题描述】:
我尝试在 vue js 上使用可重用组件,例如传递道具类名。就我而言,我使用的是顺风 css,如何使用道具传递类名。谢谢大家,周末愉快:)
这是我的html 路由器标签
router-link.button-filled(
:to="routeName"
:title="title"
:class="customClass"
)
| {{ title }}
这是我的道具
props: {
routeName: { default: "/", type: String },
title: { default: "Button", type: String },
size: { default: "md", type: String },
backgroundColor: { default: "red-500", type: String },
borderColor: { default: "red-500", type: String }
},
这是我的计算
computed: {
customClass() {
return [
"fst-bg-" + this.backgroundColor,
"fst-border-" + this.borderColor
];
}
}
【问题讨论】:
-
查看即时模式中的“动态值”(Tailwind CSS 版本 v2.1+) - 链接:tailwindcss.com/docs/just-in-time-mode#arbitrary-value-support - 建议“不能从动态值计算任意值。 "此外,所有 CSS 必须是可清除的 b/c PurgeCSS “不会尝试解析您的 HTML 并查找类属性或动态执行您的 JavaScript — 它只是在整个文件中查找与此正则表达式匹配的任何字符串”(来源: tailwindcss.com/docs/…)。祝你好运!
标签: javascript vue.js tailwind-css