【发布时间】:2022-01-25 03:51:45
【问题描述】:
我正在尝试在 Nuxt.js 2 中的自定义类上使用 @apply
nuxt.config.js
export default {
buildModules: [
'@nuxtjs/tailwindcss',
],
tailwindcss: {
cssPath: '~/assets/app.css',
exposeConfig: true
}
}
assets/app.css
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer utilities {
.btn {
@apply border-2 p-2 font-bold;
}
}
在任何 vue-single-file 或任何其他 scss 文件中
<style lang="scss">
.btn-lg {
@apply btn;
}
</style>
btn类不存在。如果您确定btn存在,请确保所有@import语句都在 Tailwind CSS 看到您的 CSS 之前得到正确处理,因为@apply只能用于同一 CSS 树中的类
那么,如何在处理之前让 Tailwind CSS 看到我的自定义样式以使我的自定义类在 @apply 中工作?
我已经尝试了以下问题和文档中的解决方案
- adding-custom-utilities
- not able to use custom classes in @apply in scss file tailwind nextjs project?
但它们都不起作用
我正在使用:
- Tailwindcss 2.2.19 通过@nuxtjs/tailwindcss
- Nuxt.js 2.15.8
非常感谢您的回复!
【问题讨论】:
-
好吧,好像是nuxtjs/tailwindcss的bug:Custom utility: @apply can only be used for classes in the same CSS tree.,加个
mode:"jit"就可以解决这个问题 -
将此作为答案发布!
标签: css nuxt.js tailwind-css