admin管理员组文章数量:1335438
I've tried using a reusable ponent on vue js like pass props class name. In my case, I'm using tailwind css. How can I pass class name using props?
this is my code
<template lang="pug">
router-link.button-filled(
:to="routeName"
:title="title"
:class="customClass"
)
| {{ title }}
</template>
<script>
export default {
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 }
},
puted: {
customClass() {
return [
"bg-" + this.backgroundColor,
"border-" + this.borderColor
];
}
}
};
</script>
This is my tailwind.config.js
module.exports = {
prefix: 'fst-',
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
And this is my master.sass
@tailwindcss base
@tailwindcss ponents
@import "./ponents/button-filled"
@import "./ponents/button-outlined"
@tailwindcss utilities
This is my result after I pass class using props. Nothing changed but class success loaded on html attribute.
I've tried using a reusable ponent on vue js like pass props class name. In my case, I'm using tailwind css. How can I pass class name using props?
this is my code
<template lang="pug">
router-link.button-filled(
:to="routeName"
:title="title"
:class="customClass"
)
| {{ title }}
</template>
<script>
export default {
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 }
},
puted: {
customClass() {
return [
"bg-" + this.backgroundColor,
"border-" + this.borderColor
];
}
}
};
</script>
This is my tailwind.config.js
module.exports = {
prefix: 'fst-',
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
And this is my master.sass
@tailwindcss base
@tailwindcss ponents
@import "./ponents/button-filled"
@import "./ponents/button-outlined"
@tailwindcss utilities
This is my result after I pass class using props. Nothing changed but class success loaded on html attribute.
Share Improve this question edited Dec 20, 2020 at 10:47 kurakura asked Dec 20, 2020 at 10:17 kurakurakurakura 1861 silver badge17 bronze badges 4- please share your tailwind.config and main css file – Boussadjra Brahim Commented Dec 20, 2020 at 10:30
- Hi @BoussadjraBrahim Wele back, how are you :), I've updated my question with tailwind.config.js and master.sass Thanks :) – kurakura Commented Dec 20, 2020 at 10:35
-
place
@tailwindcss utilities
after@tailwindcss ponents
– Boussadjra Brahim Commented Dec 20, 2020 at 10:52 - Hi @BoussadjraBrahim, still wont work, i've tried to use prefix on return but still same – kurakura Commented Dec 20, 2020 at 10:56
1 Answer
Reset to default 7Few things I noticed:
You specified a custom prefix in your
tailwind.config.js
. That means all your tailwind classes should be prefixed withfst-
. For example,text-green-500
will befst--text-green-500
in your case.You're concatenating class names in a way that will be ignored by PurgeCSS. When building your CSS for production, PostCSS goes through all your files and look for Tailwind class names according to your Tailwind config and remove all unused class names. Therefore, you should write your class names in full instead of concatenating them when using Tailwind.
Excerpt from the Tailwind documentation under Optimizing for Production.
本文标签: javascriptReactive Tailwind class with props on Vue jsStack Overflow
版权声明:本文标题:javascript - Reactive Tailwind class with props on Vue js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742365793a2461208.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论