Tailwindcss@apply指令在vue组件中不起作用

我创建了一个带有 jetstream 和惯性 vue 堆栈的 laravel 应用程序,因为我的新项目问题是Tailwindcs版本 2 postCss,它不支持@applyvue 组件内部的指令,但在.css文件内部它工作正常我不想要那个,因为那个 css 文件将加载我的每个页面我只想要带有@apply指令的短内联实用程序类,但我不能,我该如何实现。?

在我的 vue 模板中

<template>
 <div class="mt-4">
  <label for="hello">Hello</label>
  <input id="hello" class="input"/>
 </div>
</templete>

<style scoped>
    .input {
        @apply bg-gray-200 border h-10
    }
</style>

像这样在浏览器中输出

webpack.mix.js

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js').vue()
    .postCss('resources/css/app.css', 'public/css', [
        require('postcss-import'),
        require('tailwindcss'),
        require('autoprefixer'),
    ])
    .webpackConfig(require('./webpack.config'));

if (mix.inProduction()) {
    mix.version();
}

webpack.config.js

const path = require('path');

module.exports = {
    resolve: {
        alias: {
            '@': path.resolve('resources/js'),
        },
    },
};
tailwind version : "^2.0.1",
laravel version : 8.x,
jetstream version : 2.x,
inertiajs version: "^0.8.2"

回答

你必须lang="postcss"<style>标签上设置属性,因为 Tailwind 是一个 PostCSS 插件。

所以改变这个

<style scoped>
    .input {
        @apply bg-gray-200 border h-10
    }
</style>

对此

<style lang="postcss" scoped>
    .input {
        @apply bg-gray-200 border h-10
    }
</style>

  • using this approach results in follwing error :

    `Module parse failed: Unexpected token (19:0)
    File was processed with these loaders:
    * ./node_modules/vue-loader/lib/index.js
    You may need an additional loader to handle the result of these loaders.
    |
    |
    > .btn{
    | color :white;
    | }`

    Any ideas ?


以上是Tailwindcss@apply指令在vue组件中不起作用的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>